userver: userver/storages/redis/reply_types.hpp Source File
Loading...
Searching...
No Matches
reply_types.hpp
1#pragma once
2
3#include <string>
4#include <vector>
5
6#include <userver/storages/redis/impl/base.hpp>
7#include <userver/storages/redis/impl/reply/expire_reply.hpp>
8#include <userver/storages/redis/impl/reply/ttl_reply.hpp>
9#include <userver/utils/void_t.hpp>
10
11#include <userver/storages/redis/key_type.hpp>
12#include <userver/storages/redis/reply_fwd.hpp>
13#include <userver/storages/redis/scan_tag.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace storages::redis {
18
19using ExpireReply = USERVER_NAMESPACE::redis::ExpireReply;
20
21enum class HsetReply { kCreated, kUpdated };
22
23struct Point {
24 double lon;
25 double lat;
26
27 bool operator==(const Point& rhs) const { return std::tie(lon, lat) == std::tie(rhs.lon, rhs.lat); }
28};
29
30struct GeoPoint final {
31 std::string member;
32 std::optional<double> dist;
33 std::optional<uint64_t> hash;
34 std::optional<Point> point;
35
36 GeoPoint() = default;
37
38 GeoPoint(std::string member, std::optional<double> dist, std::optional<uint64_t> hash, std::optional<Point> point)
39 : member(std::move(member)), dist(dist), hash(hash), point(point) {}
40
41 bool operator==(const GeoPoint& rhs) const {
42 return std::tie(member, dist, hash, point) == std::tie(rhs.member, rhs.dist, rhs.hash, rhs.point);
43 }
44
45 bool operator!=(const GeoPoint& rhs) const { return !(*this == rhs); }
46};
47
48struct MemberScore final {
49 std::string member;
50 double score{0.0};
51
52 MemberScore() = default;
53 MemberScore(std::string member, double score) : member(std::move(member)), score(score) {}
54
55 operator std::pair<std::string, double>() const& { return {member, score}; }
56
57 operator std::pair<std::string, double>() && { return {std::move(member), score}; }
58
59 operator std::pair<const std::string, double>() const& { return {member, score}; }
60
61 operator std::pair<const std::string, double>() && { return {std::move(member), score}; }
62
63 bool operator==(const MemberScore& rhs) const { return member == rhs.member && score == rhs.score; }
64
65 bool operator!=(const MemberScore& rhs) const { return !(*this == rhs); }
66};
67
68enum class PersistReply { kKeyOrTimeoutNotFound, kTimeoutRemoved };
69
70template <ScanTag>
71struct ScanReplyElem;
72
73template <>
74struct ScanReplyElem<ScanTag::kScan> {
75 using type = std::string;
76};
77
78template <>
79struct ScanReplyElem<ScanTag::kSscan> {
80 using type = std::string;
81};
82
83template <>
84struct ScanReplyElem<ScanTag::kHscan> {
85 using type = std::pair<std::string, std::string>;
86};
87
88template <>
89struct ScanReplyElem<ScanTag::kZscan> {
90 using type = MemberScore;
91};
92
93enum class SetReply { kSet, kNotSet };
94
95enum class StatusOk { kOk };
96
97enum class StatusPong { kPong };
98
99using TtlReply = USERVER_NAMESPACE::redis::TtlReply;
100
101} // namespace storages::redis
102
103USERVER_NAMESPACE_END