userver: userver/storages/redis/transaction.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
transaction.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/redis/transaction.hpp
4/// @brief @copybrief storages::redis::Transaction
5
6#include <memory>
7#include <string>
8
9#include <userver/storages/redis/command_options.hpp>
10#include <userver/storages/redis/request.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace storages::redis {
15
16/// Atomic sequence of commands (https://redis.io/topics/transactions).
17/// Please note that Redis transaction implements isolation, but not
18/// all-or-nothing semantics (IOW a subcommand may fail, but the following
19/// subcommands will succeed).
20/// Methods will add commands to the `Transaction` object.
21/// For each added command a future-like object will be returned.
22/// You can get the result of each transaction's subcommand by calling `Get()`
23/// method for these objects.
24/// Commands will be sent to a server after calling `Exec()` that returns
25/// `RequestExec` object.
26/// You should not call `Get()` method in a future-like subcommand's object
27/// before calling `Get()` method on `RequestExec` object.
29 public:
30 enum class CheckShards { kNo, kSame };
31
32 virtual ~Transaction() = default;
33
34 /// Finish current atomic sequence of commands and send it to a server.
35 /// Returns 'future-like' request object.
36 /// The data will not be set for the future-like objects for subcommands if
37 /// `Get()` method of the returned object is not called or redis did not
38 /// return an array with command responses.
39 /// In the last case `Get()` will throw a corresponding exception.
40 virtual RequestExec Exec(const CommandControl& command_control) = 0;
41
42 // redis commands:
43
44 virtual RequestAppend Append(std::string key, std::string value) = 0;
45
46 virtual RequestDbsize Dbsize(size_t shard) = 0;
47
48 virtual RequestDel Del(std::string key) = 0;
49
50 virtual RequestDel Del(std::vector<std::string> keys) = 0;
51
52 virtual RequestUnlink Unlink(std::string key) = 0;
53
54 virtual RequestUnlink Unlink(std::vector<std::string> keys) = 0;
55
56 virtual RequestExists Exists(std::string key) = 0;
57
58 virtual RequestExists Exists(std::vector<std::string> keys) = 0;
59
60 virtual RequestExpire Expire(std::string key, std::chrono::seconds ttl) = 0;
61
62 virtual RequestGeoadd Geoadd(std::string key, GeoaddArg point_member) = 0;
63
64 virtual RequestGeoadd Geoadd(std::string key,
65 std::vector<GeoaddArg> point_members) = 0;
66
67 virtual RequestGeoradius Georadius(
68 std::string key, Longitude lon, Latitude lat, double radius,
69 const GeoradiusOptions& georadius_options) = 0;
70
71 virtual RequestGeosearch Geosearch(
72 std::string key, std::string member, double radius,
73 const GeosearchOptions& geosearch_options) = 0;
74
75 virtual RequestGeosearch Geosearch(
76 std::string key, std::string member, BoxWidth width, BoxHeight height,
77 const GeosearchOptions& geosearch_options) = 0;
78
79 virtual RequestGeosearch Geosearch(
80 std::string key, Longitude lon, Latitude lat, double radius,
81 const GeosearchOptions& geosearch_options) = 0;
82
83 virtual RequestGeosearch Geosearch(
84 std::string key, Longitude lon, Latitude lat, BoxWidth width,
85 BoxHeight height, const GeosearchOptions& geosearch_options) = 0;
86
87 virtual RequestGet Get(std::string key) = 0;
88
89 virtual RequestGetset Getset(std::string key, std::string value) = 0;
90
91 virtual RequestHdel Hdel(std::string key, std::string field) = 0;
92
93 virtual RequestHdel Hdel(std::string key,
94 std::vector<std::string> fields) = 0;
95
96 virtual RequestHexists Hexists(std::string key, std::string field) = 0;
97
98 virtual RequestHget Hget(std::string key, std::string field) = 0;
99
100 virtual RequestHgetall Hgetall(std::string key) = 0;
101
102 virtual RequestHincrby Hincrby(std::string key, std::string field,
103 int64_t increment) = 0;
104
105 virtual RequestHincrbyfloat Hincrbyfloat(std::string key, std::string field,
106 double increment) = 0;
107
108 virtual RequestHkeys Hkeys(std::string key) = 0;
109
110 virtual RequestHlen Hlen(std::string key) = 0;
111
112 virtual RequestHmget Hmget(std::string key,
113 std::vector<std::string> fields) = 0;
114
115 virtual RequestHmset Hmset(
116 std::string key,
117 std::vector<std::pair<std::string, std::string>> field_values) = 0;
118
119 virtual RequestHset Hset(std::string key, std::string field,
120 std::string value) = 0;
121
122 virtual RequestHsetnx Hsetnx(std::string key, std::string field,
123 std::string value) = 0;
124
125 virtual RequestHvals Hvals(std::string key) = 0;
126
127 virtual RequestIncr Incr(std::string key) = 0;
128
129 virtual RequestKeys Keys(std::string keys_pattern, size_t shard) = 0;
130
131 virtual RequestLindex Lindex(std::string key, int64_t index) = 0;
132
133 virtual RequestLlen Llen(std::string key) = 0;
134
135 virtual RequestLpop Lpop(std::string key) = 0;
136
137 virtual RequestLpush Lpush(std::string key, std::string value) = 0;
138
139 virtual RequestLpush Lpush(std::string key,
140 std::vector<std::string> values) = 0;
141
142 virtual RequestLpushx Lpushx(std::string key, std::string element) = 0;
143
144 virtual RequestLrange Lrange(std::string key, int64_t start,
145 int64_t stop) = 0;
146
147 virtual RequestLrem Lrem(std::string key, int64_t count,
148 std::string element) = 0;
149
150 virtual RequestLtrim Ltrim(std::string key, int64_t start, int64_t stop) = 0;
151
152 virtual RequestMget Mget(std::vector<std::string> keys) = 0;
153
154 virtual RequestMset Mset(
155 std::vector<std::pair<std::string, std::string>> key_values) = 0;
156
157 virtual RequestPersist Persist(std::string key) = 0;
158
159 virtual RequestPexpire Pexpire(std::string key,
160 std::chrono::milliseconds ttl) = 0;
161
162 virtual RequestPing Ping(size_t shard) = 0;
163
164 virtual RequestPingMessage PingMessage(size_t shard, std::string message) = 0;
165
166 virtual RequestRename Rename(std::string key, std::string new_key) = 0;
167
168 virtual RequestRpop Rpop(std::string key) = 0;
169
170 virtual RequestRpush Rpush(std::string key, std::string value) = 0;
171
172 virtual RequestRpush Rpush(std::string key,
173 std::vector<std::string> values) = 0;
174
175 virtual RequestRpushx Rpushx(std::string key, std::string element) = 0;
176
177 virtual RequestSadd Sadd(std::string key, std::string member) = 0;
178
179 virtual RequestSadd Sadd(std::string key,
180 std::vector<std::string> members) = 0;
181
182 virtual RequestScard Scard(std::string key) = 0;
183
184 virtual RequestSet Set(std::string key, std::string value) = 0;
185
186 virtual RequestSet Set(std::string key, std::string value,
187 std::chrono::milliseconds ttl) = 0;
188
189 virtual RequestSetIfExist SetIfExist(std::string key, std::string value) = 0;
190
191 virtual RequestSetIfExist SetIfExist(std::string key, std::string value,
192 std::chrono::milliseconds ttl) = 0;
193
194 virtual RequestSetIfNotExist SetIfNotExist(std::string key,
195 std::string value) = 0;
196
197 virtual RequestSetIfNotExist SetIfNotExist(std::string key, std::string value,
198 std::chrono::milliseconds ttl) = 0;
199
200 virtual RequestSetex Setex(std::string key, std::chrono::seconds seconds,
201 std::string value) = 0;
202
203 virtual RequestSismember Sismember(std::string key, std::string member) = 0;
204
205 virtual RequestSmembers Smembers(std::string key) = 0;
206
207 virtual RequestSrandmember Srandmember(std::string key) = 0;
208
209 virtual RequestSrandmembers Srandmembers(std::string key, int64_t count) = 0;
210
211 virtual RequestSrem Srem(std::string key, std::string member) = 0;
212
213 virtual RequestSrem Srem(std::string key,
214 std::vector<std::string> members) = 0;
215
216 virtual RequestStrlen Strlen(std::string key) = 0;
217
218 virtual RequestTime Time(size_t shard) = 0;
219
220 virtual RequestTtl Ttl(std::string key) = 0;
221
222 virtual RequestType Type(std::string key) = 0;
223
224 virtual RequestZadd Zadd(std::string key, double score,
225 std::string member) = 0;
226
227 virtual RequestZadd Zadd(std::string key, double score, std::string member,
228 const ZaddOptions& options) = 0;
229
230 virtual RequestZadd Zadd(
231 std::string key,
232 std::vector<std::pair<double, std::string>> scored_members) = 0;
233
234 virtual RequestZadd Zadd(
235 std::string key,
236 std::vector<std::pair<double, std::string>> scored_members,
237 const ZaddOptions& options) = 0;
238
239 virtual RequestZaddIncr ZaddIncr(std::string key, double score,
240 std::string member) = 0;
241
242 virtual RequestZaddIncrExisting ZaddIncrExisting(std::string key,
243 double score,
244 std::string member) = 0;
245
246 virtual RequestZcard Zcard(std::string key) = 0;
247
248 virtual RequestZcount Zcount(std::string key, double min, double max) = 0;
249
250 virtual RequestZrange Zrange(std::string key, int64_t start,
251 int64_t stop) = 0;
252
253 virtual RequestZrangeWithScores ZrangeWithScores(std::string key,
254 int64_t start,
255 int64_t stop) = 0;
256
257 virtual RequestZrangebyscore Zrangebyscore(std::string key, double min,
258 double max) = 0;
259
260 virtual RequestZrangebyscore Zrangebyscore(std::string key, std::string min,
261 std::string max) = 0;
262
263 virtual RequestZrangebyscore Zrangebyscore(
264 std::string key, double min, double max,
265 const RangeOptions& range_options) = 0;
266
267 virtual RequestZrangebyscore Zrangebyscore(
268 std::string key, std::string min, std::string max,
269 const RangeOptions& range_options) = 0;
270
271 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
272 std::string key, double min, double max) = 0;
273
274 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
275 std::string key, std::string min, std::string max) = 0;
276
277 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
278 std::string key, double min, double max,
279 const RangeOptions& range_options) = 0;
280
281 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
282 std::string key, std::string min, std::string max,
283 const RangeOptions& range_options) = 0;
284
285 virtual RequestZrem Zrem(std::string key, std::string member) = 0;
286
287 virtual RequestZrem Zrem(std::string key,
288 std::vector<std::string> members) = 0;
289
290 virtual RequestZremrangebyrank Zremrangebyrank(std::string key, int64_t start,
291 int64_t stop) = 0;
292
293 virtual RequestZremrangebyscore Zremrangebyscore(std::string key, double min,
294 double max) = 0;
295
296 virtual RequestZremrangebyscore Zremrangebyscore(std::string key,
297 std::string min,
298 std::string max) = 0;
299
300 virtual RequestZscore Zscore(std::string key, std::string member) = 0;
301
302 // end of redis commands
303};
304
306
307class EmptyTransactionException : public USERVER_NAMESPACE::redis::Exception {
308 public:
309 using USERVER_NAMESPACE::redis::Exception::Exception;
310};
311
313 : public USERVER_NAMESPACE::redis::Exception {
314 public:
315 using USERVER_NAMESPACE::redis::Exception::Exception;
316};
317
318} // namespace storages::redis
319
320USERVER_NAMESPACE_END