10#include <userver/storages/redis/base.hpp>
11#include <userver/storages/redis/command_control.hpp>
12#include <userver/storages/redis/exception.hpp>
13#include <userver/storages/redis/scan_tag.hpp>
15USERVER_NAMESPACE_BEGIN
17namespace storages::
redis {
25 std::optional<size_t> offset;
26 std::optional<size_t> count;
36 enum class Sort { kNone, kAsc, kDesc };
37 enum class Unit { kM, kKm, kMi, kFt };
40 bool withcoord =
false;
41 bool withdist =
false;
42 bool withhash =
false;
44 Sort sort = Sort::kNone;
48 enum class Sort { kNone, kAsc, kDesc };
49 enum class Unit { kM, kKm, kMi, kFt };
52 bool withcoord =
false;
53 bool withdist =
false;
54 bool withhash =
false;
56 Sort sort = Sort::kNone;
60 enum class Exist { kAddAlways, kAddIfNotExist, kAddIfExist };
61 enum class Compare { kNone, kGreaterThan, kLessThan };
62 enum class ReturnValue { kAddedCount, kChangedCount };
64 ZaddOptions() =
default;
65 constexpr ZaddOptions(
67 ReturnValue return_value = ReturnValue::kAddedCount,
68 Compare compare = Compare::kNone
72 return_value(return_value)
74 constexpr ZaddOptions(Exist exist, Compare compare, ReturnValue return_value = ReturnValue::kAddedCount)
77 return_value(return_value)
80 constexpr ZaddOptions(ReturnValue return_value, Exist exist = Exist::kAddAlways, Compare compare = Compare::kNone)
83 return_value(return_value)
85 constexpr ZaddOptions(ReturnValue return_value, Compare compare, Exist exist = Exist::kAddAlways)
88 return_value(return_value)
91 constexpr ZaddOptions(
93 Exist exist = Exist::kAddAlways,
94 ReturnValue return_value = ReturnValue::kAddedCount
98 return_value(return_value)
100 constexpr ZaddOptions(Compare compare, ReturnValue return_value, Exist exist = Exist::kAddAlways)
103 return_value(return_value)
106 Exist exist = Exist::kAddAlways;
107 Compare compare = Compare::kNone;
108 ReturnValue return_value = ReturnValue::kAddedCount;
112 return {exist, return_value};
117 return {compare, return_value};
120 return {return_value, exist};
123 return {return_value, compare};
132 explicit Match(std::string value)
133 : value_(std::move(value))
136 const std::string& Get()
const& {
return value_; }
138 std::string Get() && {
return std::move(value_); }
147 explicit constexpr Count(std::size_t value)
noexcept : value_(value) {}
149 constexpr std::size_t Get()
const noexcept {
return value_; }
158 using Match = storages::
redis::Match;
159 using Count = storages::
redis::Count;
161 ScanOptionsGeneric() =
default;
169 template <
typename... Args>
170 ScanOptionsGeneric(Args... args) {
171 (Apply(std::move(args)), ...);
174 const std::optional<Match>& GetMatchOptional()
const noexcept {
return pattern_; }
176 const std::optional<Count>& GetCountOptional()
const noexcept {
return count_; }
178 std::optional<Match> ExtractMatch()
noexcept {
return std::move(pattern_); }
180 std::optional<Count> ExtractCount()
noexcept {
return std::move(count_); }
183 void Apply(Match pattern) {
187 pattern_ = std::move(pattern);
190 void Apply(Count count) {
197 std::optional<Match> pattern_;
198 std::optional<Count> count_;
202using ScanOptionsTmpl [[deprecated(
"Just use ScanOptionsGeneric")]] =
ScanOptionsGeneric;
210 enum class Exist { kSetAlways, kSetIfNotExist, kSetIfExist };
213 int milliseconds = 0;
214 Exist exist = Exist::kSetAlways;
218 enum class Exist { kSetAlways, kSetIfNotExist, kSetIfExist };
219 enum class Compare { kNone, kGreaterThan, kLessThan };
221 ExpireOptions() =
default;
222 constexpr ExpireOptions(Exist exist, Compare compare = Compare::kNone)
226 if (exist == Exist::kSetIfNotExist && compare != Compare::kNone) {
228 throw std::invalid_argument(
"When exist is kSetIfNotExist, compare must be kNone");
232 constexpr ExpireOptions(Compare compare, Exist exist = Exist::kSetAlways)
236 if (exist == Exist::kSetIfNotExist && compare != Compare::kNone) {
238 throw std::invalid_argument(
"When exist is kSetIfNotExist, compare must be kNone");
242 Exist exist = Exist::kSetAlways;
243 Compare compare = Compare::kNone;
247 bool withscores =
false;