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 {
28 return std::tie(lon, lat) == std::tie(rhs.lon, rhs.lat);
29 }
30};
31
32struct GeoPoint final {
33 std::string member;
34 std::optional<double> dist;
35 std::optional<uint64_t> hash;
36 std::optional<Point> point;
37
38 GeoPoint() = default;
39
40 GeoPoint(std::string member, std::optional<double> dist,
41 std::optional<uint64_t> hash, std::optional<Point> point)
42 : member(std::move(member)), dist(dist), hash(hash), point(point) {}
43
44 bool operator==(const GeoPoint& rhs) const {
45 return std::tie(member, dist, hash, point) ==
46 std::tie(rhs.member, rhs.dist, rhs.hash, rhs.point);
47 }
48
49 bool operator!=(const GeoPoint& rhs) const { return !(*this == rhs); }
50};
51
52struct MemberScore final {
53 std::string member;
54 double score{0.0};
55
56 MemberScore() = default;
57 MemberScore(std::string member, double score)
58 : member(std::move(member)), score(score) {}
59
60 operator std::pair<std::string, double>() const& { return {member, score}; }
61
62 operator std::pair<std::string, double>() && {
63 return {std::move(member), score};
64 }
65
66 operator std::pair<const std::string, double>() const& {
67 return {member, score};
68 }
69
70 operator std::pair<const std::string, double>() && {
71 return {std::move(member), score};
72 }
73
74 bool operator==(const MemberScore& rhs) const {
75 return member == rhs.member && score == rhs.score;
76 }
77
78 bool operator!=(const MemberScore& rhs) const { return !(*this == rhs); }
79};
80
81enum class PersistReply { kKeyOrTimeoutNotFound, kTimeoutRemoved };
82
83template <ScanTag>
84struct ScanReplyElem;
85
86template <>
87struct ScanReplyElem<ScanTag::kScan> {
88 using type = std::string;
89};
90
91template <>
92struct ScanReplyElem<ScanTag::kSscan> {
93 using type = std::string;
94};
95
96template <>
97struct ScanReplyElem<ScanTag::kHscan> {
98 using type = std::pair<std::string, std::string>;
99};
100
101template <>
102struct ScanReplyElem<ScanTag::kZscan> {
103 using type = MemberScore;
104};
105
106enum class SetReply { kSet, kNotSet };
107
108enum class StatusOk { kOk };
109
110enum class StatusPong { kPong };
111
112using TtlReply = USERVER_NAMESPACE::redis::TtlReply;
113
114} // namespace storages::redis
115
116USERVER_NAMESPACE_END