userver: userver/storages/redis/impl/command_options.hpp Source File
Loading...
Searching...
No Matches
command_options.hpp
1#pragma once
2
3#include <optional>
4#include <string>
5#include <vector>
6
7#include <userver/storages/redis/impl/base.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace redis {
12
13using Longitude = utils::StrongTypedef<struct LongitudeTag, double>;
14using Latitude = utils::StrongTypedef<struct LatitudeTag, double>;
15using BoxWidth = utils::StrongTypedef<struct BoxWidthTag, double>;
16using BoxHeight = utils::StrongTypedef<struct BoxHeightTag, double>;
17
18struct GeoaddArg {
19 double lon;
20 double lat;
21 std::string member;
22};
23
24struct GeoradiusOptions {
25 enum class Sort { kNone, kAsc, kDesc };
26 enum class Unit { kM, kKm, kMi, kFt };
27
28 Unit unit = Unit::kM;
29 bool withcoord = false;
30 bool withdist = false;
31 bool withhash = false;
32 size_t count = 0;
33 Sort sort = Sort::kNone;
34};
35
36struct GeosearchOptions {
37 enum class Sort { kNone, kAsc, kDesc };
38 enum class Unit { kM, kKm, kMi, kFt };
39
40 Unit unit = Unit::kM;
41 bool withcoord = false;
42 bool withdist = false;
43 bool withhash = false;
44 size_t count = 0;
45 Sort sort = Sort::kNone;
46};
47
48struct SetOptions {
49 enum class Exist { kSetAlways, kSetIfNotExist, kSetIfExist };
50
51 int seconds = 0;
52 int milliseconds = 0;
53 Exist exist = Exist::kSetAlways;
54};
55
56struct ZaddOptions {
57 enum class Exist { kAddAlways, kAddIfNotExist, kAddIfExist };
58 enum class ReturnValue { kAddedCount, kChangedCount };
59
60 ZaddOptions() = default;
61 ZaddOptions(Exist exist, ReturnValue return_value = ReturnValue::kAddedCount)
62 : exist(exist), return_value(return_value) {}
63 ZaddOptions(ReturnValue return_value, Exist exist = Exist::kAddAlways)
64 : exist(exist), return_value(return_value) {}
65
66 Exist exist = Exist::kAddAlways;
67 ReturnValue return_value = ReturnValue::kAddedCount;
68};
69
70ZaddOptions operator|(ZaddOptions::Exist exist,
71 ZaddOptions::ReturnValue return_value);
72ZaddOptions operator|(ZaddOptions::ReturnValue return_value,
73 ZaddOptions::Exist exist);
74
75struct ScanOptions {
76 std::optional<ScanCursor> cursor;
77 std::optional<std::string> pattern;
78 std::optional<size_t> count;
79};
80
81struct ScoreOptions {
82 bool withscores = false;
83};
84
85struct RangeOptions {
86 std::optional<size_t> offset;
87 std::optional<size_t> count;
88};
89
90struct RangeScoreOptions {
91 ScoreOptions score_options;
92 RangeOptions range_options;
93};
94
95void PutArg(CmdArgs::CmdArgsArray& args_, GeoaddArg arg);
96
97void PutArg(CmdArgs::CmdArgsArray& args_, std::vector<GeoaddArg> arg);
98
99void PutArg(CmdArgs::CmdArgsArray& args_, const GeoradiusOptions& arg);
100
101void PutArg(CmdArgs::CmdArgsArray& args_, const GeosearchOptions& arg);
102
103void PutArg(CmdArgs::CmdArgsArray& args_, const SetOptions& arg);
104
105void PutArg(CmdArgs::CmdArgsArray& args_, const ZaddOptions& arg);
106
107void PutArg(CmdArgs::CmdArgsArray& args_, const ScanOptions& arg);
108
109void PutArg(CmdArgs::CmdArgsArray& args_, const ScoreOptions& arg);
110
111void PutArg(CmdArgs::CmdArgsArray& args_, const RangeOptions& arg);
112
113void PutArg(CmdArgs::CmdArgsArray& args_, const RangeScoreOptions& arg);
114
115} // namespace redis
116
117USERVER_NAMESPACE_END