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
70 : exist(exist), compare(compare), return_value(return_value) {}
71 constexpr ZaddOptions(Exist exist, Compare compare, ReturnValue return_value = ReturnValue::kAddedCount)
72 : exist(exist), compare(compare), return_value(return_value) {}
74 constexpr ZaddOptions(ReturnValue return_value, Exist exist = Exist::kAddAlways, Compare compare = Compare::kNone)
75 : exist(exist), compare(compare), return_value(return_value) {}
76 constexpr ZaddOptions(ReturnValue return_value, Compare compare, Exist exist = Exist::kAddAlways)
77 : exist(exist), compare(compare), return_value(return_value) {}
79 constexpr ZaddOptions(
81 Exist exist = Exist::kAddAlways,
82 ReturnValue return_value = ReturnValue::kAddedCount
84 : exist(exist), compare(compare), return_value(return_value) {}
85 constexpr ZaddOptions(Compare compare, ReturnValue return_value, Exist exist = Exist::kAddAlways)
86 : exist(exist), compare(compare), return_value(return_value) {}
88 Exist exist = Exist::kAddAlways;
89 Compare compare = Compare::kNone;
90 ReturnValue return_value = ReturnValue::kAddedCount;
94 return {exist, return_value};
99 return {compare, return_value};
102 return {return_value, exist};
105 return {return_value, compare};
114 explicit Match(std::string value) : value_(std::move(value)) {}
116 const std::string& Get()
const& {
return value_; }
118 std::string Get() && {
return std::move(value_); }
127 explicit constexpr Count(std::size_t value)
noexcept : value_(value) {}
129 constexpr std::size_t Get()
const noexcept {
return value_; }
138 using Match = storages::
redis::Match;
139 using Count = storages::
redis::Count;
141 ScanOptionsGeneric() =
default;
149 template <
typename... Args>
150 ScanOptionsGeneric(Args... args) {
151 (Apply(std::move(args)), ...);
154 const std::optional<Match>& GetMatchOptional()
const noexcept {
return pattern_; }
156 const std::optional<Count>& GetCountOptional()
const noexcept {
return count_; }
158 std::optional<Match> ExtractMatch()
noexcept {
return std::move(pattern_); }
160 std::optional<Count> ExtractCount()
noexcept {
return std::move(count_); }
163 void Apply(Match pattern) {
165 pattern_ = std::move(pattern);
168 void Apply(Count count) {
173 std::optional<Match> pattern_;
174 std::optional<Count> count_;
178using ScanOptionsTmpl [[deprecated(
"Just use ScanOptionsGeneric")]] =
ScanOptionsGeneric;
186 enum class Exist { kSetAlways, kSetIfNotExist, kSetIfExist };
189 int milliseconds = 0;
190 Exist exist = Exist::kSetAlways;
194 bool withscores =
false;