userver: userver/storages/redis/client.hpp Source File
Loading...
Searching...
No Matches
client.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/redis/client.hpp
4/// @brief Valkey or Redis client
5
6#include <chrono>
7#include <memory>
8#include <string>
9
10#include <userver/storages/redis/base.hpp>
11#include <userver/storages/redis/health_check_param.hpp>
12
13#include <userver/storages/redis/bit_operation.hpp>
14#include <userver/storages/redis/client_fwd.hpp>
15#include <userver/storages/redis/command_options.hpp>
16#include <userver/storages/redis/request.hpp>
17#include <userver/storages/redis/request_eval.hpp>
18#include <userver/storages/redis/request_evalsha.hpp>
19#include <userver/storages/redis/request_generic.hpp>
20#include <userver/storages/redis/transaction.hpp>
21
22USERVER_NAMESPACE_BEGIN
23
24namespace storages::redis {
25
26enum class PubShard {
27 kZeroShard,
28 kRoundRobin,
29};
30
31/// @ingroup userver_clients
32///
33/// @brief Valkey or Redis client.
34///
35/// Usually retrieved from components::Redis component.
36///
37/// ## Example usage:
38///
39/// @snippet redis/src/storages/redis/client_redistest.cpp Sample Redis Client usage
40class Client {
41public:
42 virtual ~Client() = default;
43
44 virtual size_t ShardsCount() const = 0;
45 virtual bool IsInClusterMode() const = 0;
46
47 virtual size_t ShardByKey(const std::string& key) const = 0;
48
49 void CheckShardIdx(size_t shard_idx) const;
50
51 virtual void WaitConnectedOnce(RedisWaitConnected wait_connected) = 0;
52 virtual bool IsReady(const HealthCheckParams& params) const = 0;
53
54 bool IsReady(WaitConnectedMode mode) const { return IsReady(HealthCheckParams{mode, 0, 0}); }
55
56 // redis commands:
57
58 virtual RequestAppend Append(std::string key, std::string value, const CommandControl& command_control) = 0;
59
60 virtual RequestBitop Bitop(
61 BitOperation op,
62 std::string dest_key,
63 std::vector<std::string> src_keys,
64 const CommandControl& command_control
65 ) = 0;
66
67 virtual RequestDbsize Dbsize(size_t shard, const CommandControl& command_control) = 0;
68
69 virtual RequestDecr Decr(std::string key, const CommandControl& command_control) = 0;
70
71 virtual RequestDel Del(std::string key, const CommandControl& command_control) = 0;
72
73 virtual RequestDel Del(std::vector<std::string> keys, const CommandControl& command_control) = 0;
74
75 virtual RequestUnlink Unlink(std::string key, const CommandControl& command_control) = 0;
76
77 virtual RequestUnlink Unlink(std::vector<std::string> keys, const CommandControl& command_control) = 0;
78
79 /// @brief Invoke the execution of a server-side Lua script.
80 ///
81 /// For huge scripts consider EvalSha() to save network bandwidth.
82 ///
83 /// Sample usage:
84 /// @snippet redis/src/storages/redis/client_cluster_redistest.cpp Sample eval usage
85 template <typename ScriptResult, typename ReplyType = ScriptResult>
86 RequestEval<ScriptResult, ReplyType> Eval(
87 std::string script,
88 std::vector<std::string> keys,
89 std::vector<std::string> args,
90 const CommandControl& command_control
91 ) {
92 return RequestEval<ScriptResult, ReplyType>{
93 EvalCommon(std::move(script), std::move(keys), std::move(args), command_control)
94 };
95 }
96
97 /// @brief Invoke the execution of a server-side Lua script that was previously uploaded to the server via
98 /// ScriptLoad() member function.
99 ///
100 /// For small scripts consider using a simpler Eval() member function.
101 ///
102 /// Sample usage:
103 /// @snippet redis/src/storages/redis/client_cluster_redistest.cpp Sample evalsha usage
104 template <typename ScriptResult, typename ReplyType = ScriptResult>
105 RequestEvalSha<ScriptResult, ReplyType> EvalSha(
106 std::string script_hash,
107 std::vector<std::string> keys,
108 std::vector<std::string> args,
109 const CommandControl& command_control
110 ) {
111 return RequestEvalSha<ScriptResult, ReplyType>{
112 EvalShaCommon(std::move(script_hash), std::move(keys), std::move(args), command_control)
113 };
114 }
115
116 /// @brief This is a read-only variant of the Eval() command that cannot execute commands that modify data.
117 ///
118 /// For huge scripts consider EvalShaReadOnly() to save network bandwidth.
119 ///
120 /// Sample usage:
121 /// @snippet redis/src/storages/redis/client_cluster_redistest.cpp Sample eval_ro usage
122 template <typename ScriptResult, typename ReplyType = ScriptResult>
123 RequestEval<ScriptResult, ReplyType> EvalReadOnly(
124 std::string script,
125 std::vector<std::string> keys,
126 std::vector<std::string> args,
127 const CommandControl& command_control
128 ) {
129 return RequestEval<ScriptResult, ReplyType>{
130 EvalReadOnlyCommon(std::move(script), std::move(keys), std::move(args), command_control)
131 };
132 }
133
134 /// @brief This is a read-only variant of the EvalSha() command that cannot execute commands that modify data.
135 ///
136 /// For small scripts consider using a simpler EvalReadOnly() member function.
137 ///
138 /// Sample usage:
139 /// @snippet redis/src/storages/redis/client_cluster_redistest.cpp Sample evalsha_ro usage
140 template <typename ScriptResult, typename ReplyType = ScriptResult>
141 RequestEvalSha<ScriptResult, ReplyType> EvalShaReadOnly(
142 std::string script_hash,
143 std::vector<std::string> keys,
144 std::vector<std::string> args,
145 const CommandControl& command_control
146 ) {
147 return RequestEvalSha<ScriptResult, ReplyType>{
148 EvalShaReadOnlyCommon(std::move(script_hash), std::move(keys), std::move(args), command_control)
149 };
150 }
151
152 /// @brief Execute a custom Redis command.
153 /// @param command Redis command name
154 /// @param args command arguments
155 /// @param key_index Index of the key in the args vector used to determine the shard
156 /// @param command_control per-command execution options
157 ///
158 /// Sample usage:
159 /// @snippet redis/src/storages/redis/client_cluster_redistest.cpp Sample generic command usage
160 template <typename ReplyType>
161 RequestGeneric<ReplyType> GenericCommand(
162 std::string command,
163 std::vector<std::string> args,
164 size_t key_index,
165 const CommandControl& command_control
166 ) {
167 return RequestGeneric<ReplyType>{GenericCommon(std::move(command), std::move(args), key_index, command_control)
168 };
169 }
170
171 /// @brief Load the script to the server for further execution via EvalSha() member function.
172 ///
173 /// Sample usage:
174 /// @snippet redis/src/storages/redis/client_cluster_redistest.cpp Sample evalsha usage
175 virtual RequestScriptLoad ScriptLoad(std::string script, size_t shard, const CommandControl& command_control) = 0;
176
177 /// @overload
178 template <typename ScriptInfo, typename ReplyType = std::decay_t<ScriptInfo>>
179 RequestEval<std::decay_t<ScriptInfo>, ReplyType> Eval(
180 const ScriptInfo& script_info,
181 std::vector<std::string> keys,
182 std::vector<std::string> args,
183 const CommandControl& command_control
184 ) {
185 return RequestEval<std::decay_t<ScriptInfo>, ReplyType>{
186 EvalCommon(script_info.GetScript(), std::move(keys), std::move(args), command_control)
187 };
188 }
189
190 virtual RequestExists Exists(std::string key, const CommandControl& command_control) = 0;
191
192 virtual RequestExists Exists(std::vector<std::string> keys, const CommandControl& command_control) = 0;
193
194 virtual RequestExpire Expire(std::string key, std::chrono::seconds ttl, const CommandControl& command_control) = 0;
195
196 virtual RequestExpire Expire(
197 std::string key,
198 std::chrono::seconds ttl,
199 ExpireOptions options,
200 const CommandControl& command_control
201 ) = 0;
202
203 virtual RequestGeoadd Geoadd(std::string key, GeoaddArg point_member, const CommandControl& command_control) = 0;
204
205 virtual RequestGeoadd Geoadd(
206 std::string key,
207 std::vector<GeoaddArg> point_members,
208 const CommandControl& command_control
209 ) = 0;
210
211 virtual RequestGeopos Geopos(
212 std::string key,
213 std::vector<std::string> members,
214 const CommandControl& command_control
215 ) = 0;
216
217 virtual RequestGeoradius Georadius(
218 std::string key,
219 Longitude lon,
220 Latitude lat,
221 double radius,
222 const GeoradiusOptions& georadius_options,
223 const CommandControl& command_control
224 ) = 0;
225
226 virtual RequestGeosearch Geosearch(
227 std::string key,
228 std::string member,
229 double radius,
230 const GeosearchOptions& geosearch_options,
231 const CommandControl& command_control
232 ) = 0;
233
234 virtual RequestGeosearch Geosearch(
235 std::string key,
236 std::string member,
237 BoxWidth width,
238 BoxHeight height,
239 const GeosearchOptions& geosearch_options,
240 const CommandControl& command_control
241 ) = 0;
242
243 virtual RequestGeosearch Geosearch(
244 std::string key,
245 Longitude lon,
246 Latitude lat,
247 double radius,
248 const GeosearchOptions& geosearch_options,
249 const CommandControl& command_control
250 ) = 0;
251
252 virtual RequestGeosearch Geosearch(
253 std::string key,
254 Longitude lon,
255 Latitude lat,
256 BoxWidth width,
257 BoxHeight height,
258 const GeosearchOptions& geosearch_options,
259 const CommandControl& command_control
260 ) = 0;
261
262 virtual RequestGet Get(std::string key, const CommandControl& command_control) = 0;
263
264 virtual RequestGetdel Getdel(std::string key, const CommandControl& command_control) = 0;
265
266 virtual RequestGetset Getset(std::string key, std::string value, const CommandControl& command_control) = 0;
267
268 virtual RequestHdel Hdel(std::string key, std::string field, const CommandControl& command_control) = 0;
269
270 virtual RequestHdel Hdel(
271 std::string key,
272 std::vector<std::string> fields,
273 const CommandControl& command_control
274 ) = 0;
275
276 virtual RequestHexists Hexists(std::string key, std::string field, const CommandControl& command_control) = 0;
277
278 virtual RequestHget Hget(std::string key, std::string field, const CommandControl& command_control) = 0;
279
280 // use Hscan in case of a big hash
281 virtual RequestHgetall Hgetall(std::string key, const CommandControl& command_control) = 0;
282
283 virtual RequestHincrby Hincrby(
284 std::string key,
285 std::string field,
286 int64_t increment,
287 const CommandControl& command_control
288 ) = 0;
289
290 virtual RequestHincrbyfloat Hincrbyfloat(
291 std::string key,
292 std::string field,
293 double increment,
294 const CommandControl& command_control
295 ) = 0;
296
297 // use Hscan in case of a big hash
298 virtual RequestHkeys Hkeys(std::string key, const CommandControl& command_control) = 0;
299
300 virtual RequestHlen Hlen(std::string key, const CommandControl& command_control) = 0;
301
302 virtual RequestHmget Hmget(
303 std::string key,
304 std::vector<std::string> fields,
305 const CommandControl& command_control
306 ) = 0;
307
308 virtual RequestHmset Hmset(
309 std::string key,
310 std::vector<std::pair<std::string, std::string>> field_values,
311 const CommandControl& command_control
312 ) = 0;
313
314 /// @brief Iterate over a collection of elements.
315 ///
316 /// Sample usage:
317 /// @snippet redis/src/storages/redis/client_scan_redistest.cpp Sample Hscan usage
318 virtual RequestHscan Hscan(std::string key, HscanOptions options, const CommandControl& command_control) = 0;
319
320 virtual RequestHset Hset(
321 std::string key,
322 std::string field,
323 std::string value,
324 const CommandControl& command_control
325 ) = 0;
326
327 virtual RequestHsetnx Hsetnx(
328 std::string key,
329 std::string field,
330 std::string value,
331 const CommandControl& command_control
332 ) = 0;
333
334 // use Hscan in case of a big hash
335 virtual RequestHvals Hvals(std::string key, const CommandControl& command_control) = 0;
336
337 virtual RequestIncr Incr(std::string key, const CommandControl& command_control) = 0;
338
339 [[deprecated("use Scan")]] virtual RequestKeys Keys(
340 std::string keys_pattern,
341 size_t shard,
342 const CommandControl& command_control
343 ) = 0;
344
345 virtual RequestLindex Lindex(std::string key, int64_t index, const CommandControl& command_control) = 0;
346
347 virtual RequestLlen Llen(std::string key, const CommandControl& command_control) = 0;
348
349 virtual RequestLpop Lpop(std::string key, const CommandControl& command_control) = 0;
350
351 virtual RequestLpush Lpush(std::string key, std::string value, const CommandControl& command_control) = 0;
352
353 virtual RequestLpush Lpush(
354 std::string key,
355 std::vector<std::string> values,
356 const CommandControl& command_control
357 ) = 0;
358
359 virtual RequestLpushx Lpushx(std::string key, std::string element, const CommandControl& command_control) = 0;
360
361 virtual RequestLrange Lrange(
362 std::string key,
363 int64_t start,
364 int64_t stop,
365 const CommandControl& command_control
366 ) = 0;
367
368 virtual RequestLrem Lrem(
369 std::string key,
370 int64_t count,
371 std::string element,
372 const CommandControl& command_control
373 ) = 0;
374
375 virtual RequestLtrim Ltrim(std::string key, int64_t start, int64_t stop, const CommandControl& command_control) = 0;
376
377 virtual RequestMget Mget(std::vector<std::string> keys, const CommandControl& command_control) = 0;
378
379 virtual RequestMset Mset(
380 std::vector<std::pair<std::string, std::string>> key_values,
381 const CommandControl& command_control
382 ) = 0;
383
384 /// @brief Atomically set multiple key-value pairs, without an expiration clause.
385 ///
386 /// Available since Valkey 9.1.0 and Redis 8.4.0. In cluster mode all keys
387 /// must belong to the same hash slot; use a common hash tag to ensure that.
388 /// @throws InvalidArgumentException in cluster mode if the keys belong to different hash slots
389 virtual RequestMsetex Msetex(
390 std::vector<std::pair<std::string, std::string>> key_values,
391 const CommandControl& command_control
392 ) = 0;
393
394 /// @brief Atomically set multiple key-value pairs with optional existence and TTL conditions.
395 ///
396 /// Available since Valkey 9.1.0 and Redis 8.4.0. In cluster mode all keys
397 /// must belong to the same hash slot; use a common hash tag to ensure that.
398 /// @throws InvalidArgumentException in cluster mode if the keys belong to different hash slots
399 virtual RequestMsetex Msetex(
400 std::vector<std::pair<std::string, std::string>> key_values,
401 MsetexOptions options,
402 const CommandControl& command_control
403 ) = 0;
404
405 virtual TransactionPtr Multi() = 0;
406
407 virtual TransactionPtr Multi(Transaction::CheckShards check_shards) = 0;
408
409 virtual RequestPersist Persist(std::string key, const CommandControl& command_control) = 0;
410
411 virtual RequestPexpire Pexpire(
412 std::string key,
413 std::chrono::milliseconds ttl,
414 const CommandControl& command_control
415 ) = 0;
416
417 virtual RequestPing Ping(size_t shard, const CommandControl& command_control) = 0;
418
419 virtual RequestPingMessage Ping(size_t shard, std::string message, const CommandControl& command_control) = 0;
420
421 virtual void Publish(
422 std::string channel,
423 std::string message,
424 const CommandControl& command_control,
425 PubShard policy
426 ) = 0;
427
428 virtual void Spublish(std::string channel, std::string message, const CommandControl& command_control) = 0;
429
430 virtual RequestRename Rename(std::string key, std::string new_key, const CommandControl& command_control) = 0;
431
432 virtual RequestRpop Rpop(std::string key, const CommandControl& command_control) = 0;
433
434 virtual RequestRpush Rpush(std::string key, std::string value, const CommandControl& command_control) = 0;
435
436 virtual RequestRpush Rpush(
437 std::string key,
438 std::vector<std::string> values,
439 const CommandControl& command_control
440 ) = 0;
441
442 virtual RequestRpushx Rpushx(std::string key, std::string element, const CommandControl& command_control) = 0;
443
444 /// @brief Add member to a set of elements.
445 ///
446 /// Sample usage:
447 /// @snippet redis/src/storages/redis/client_scan_redistest.cpp Sample Sadd and Sscan usage
448 virtual RequestSadd Sadd(std::string key, std::string member, const CommandControl& command_control) = 0;
449
450 /// @overload
451 virtual RequestSadd Sadd(
452 std::string key,
453 std::vector<std::string> members,
454 const CommandControl& command_control
455 ) = 0;
456
457 /// @brief Iterate over a collection of elements.
458 ///
459 /// Sample usage:
460 /// @snippet redis/src/storages/redis/client_scan_redistest.cpp Sample Scan usage
461 virtual RequestScan Scan(size_t shard, ScanOptions options, const CommandControl& command_control) = 0;
462
463 virtual RequestScard Scard(std::string key, const CommandControl& command_control) = 0;
464
465 virtual RequestSet Set(std::string key, std::string value, const CommandControl& command_control) = 0;
466
467 virtual RequestSet Set(
468 std::string key,
469 std::string value,
470 std::chrono::milliseconds ttl,
471 const CommandControl& command_control
472 ) = 0;
473
474 virtual RequestSetIfExist SetIfExist(std::string key, std::string value, const CommandControl& command_control) = 0;
475
476 virtual RequestSetIfExist SetIfExist(
477 std::string key,
478 std::string value,
479 std::chrono::milliseconds ttl,
480 const CommandControl& command_control
481 ) = 0;
482
483 virtual RequestSetIfNotExist SetIfNotExist(
484 std::string key,
485 std::string value,
486 const CommandControl& command_control
487 ) = 0;
488
489 virtual RequestSetIfNotExist SetIfNotExist(
490 std::string key,
491 std::string value,
492 std::chrono::milliseconds ttl,
493 const CommandControl& command_control
494 ) = 0;
495
496 virtual RequestSetIfNotExistOrGet SetIfNotExistOrGet(
497 std::string key,
498 std::string value,
499 const CommandControl& command_control
500 ) = 0;
501
502 virtual RequestSetIfNotExistOrGet SetIfNotExistOrGet(
503 std::string key,
504 std::string value,
505 std::chrono::milliseconds ttl,
506 const CommandControl& command_control
507 ) = 0;
508
509 virtual RequestSetex Setex(
510 std::string key,
511 std::chrono::seconds seconds,
512 std::string value,
513 const CommandControl& command_control
514 ) = 0;
515
516 virtual RequestSetAndGetPrevious SetAndGetPrevious(
517 std::string key,
518 std::string value,
519 std::chrono::milliseconds ttl,
520 const CommandControl& command_control
521 ) = 0;
522
523 virtual RequestSismember Sismember(std::string key, std::string member, const CommandControl& command_control) = 0;
524
525 // use Sscan in case of a big set
526 virtual RequestSmembers Smembers(std::string key, const CommandControl& command_control) = 0;
527
528 virtual RequestSrandmember Srandmember(std::string key, const CommandControl& command_control) = 0;
529
530 virtual RequestSrandmembers Srandmembers(std::string key, int64_t count, const CommandControl& command_control) = 0;
531
532 virtual RequestSrem Srem(std::string key, std::string member, const CommandControl& command_control) = 0;
533
534 virtual RequestSrem Srem(
535 std::string key,
536 std::vector<std::string> members,
537 const CommandControl& command_control
538 ) = 0;
539
540 /// @brief Iterate over a collection of elements.
541 ///
542 /// Sample usage:
543 /// @snippet redis/src/storages/redis/client_scan_redistest.cpp Sample Sadd and Sscan usage
544 virtual RequestSscan Sscan(std::string key, SscanOptions options, const CommandControl& command_control) = 0;
545
546 virtual RequestStrlen Strlen(std::string key, const CommandControl& command_control) = 0;
547
548 virtual RequestTime Time(size_t shard, const CommandControl& command_control) = 0;
549
550 virtual RequestTtl Ttl(std::string key, const CommandControl& command_control) = 0;
551
552 virtual RequestType Type(std::string key, const CommandControl& command_control) = 0;
553
554 virtual RequestZadd Zadd(
555 std::string key,
556 double score,
557 std::string member,
558 const CommandControl& command_control
559 ) = 0;
560
561 virtual RequestZadd Zadd(
562 std::string key,
563 double score,
564 std::string member,
565 const ZaddOptions& options,
566 const CommandControl& command_control
567 ) = 0;
568
569 virtual RequestZadd Zadd(
570 std::string key,
571 std::vector<std::pair<double, std::string>> scored_members,
572 const CommandControl& command_control
573 ) = 0;
574
575 virtual RequestZadd Zadd(
576 std::string key,
577 std::vector<std::pair<double, std::string>> scored_members,
578 const ZaddOptions& options,
579 const CommandControl& command_control
580 ) = 0;
581
582 virtual RequestZaddIncr ZaddIncr(
583 std::string key,
584 double score,
585 std::string member,
586 const CommandControl& command_control
587 ) = 0;
588
589 virtual RequestZaddIncrExisting ZaddIncrExisting(
590 std::string key,
591 double score,
592 std::string member,
593 const CommandControl& command_control
594 ) = 0;
595
596 virtual RequestZcard Zcard(std::string key, const CommandControl& command_control) = 0;
597
598 virtual RequestZcount Zcount(std::string key, double min, double max, const CommandControl& command_control) = 0;
599
600 virtual RequestZrange Zrange(
601 std::string key,
602 int64_t start,
603 int64_t stop,
604 const CommandControl& command_control
605 ) = 0;
606
607 virtual RequestZrangeWithScores ZrangeWithScores(
608 std::string key,
609 int64_t start,
610 int64_t stop,
611 const CommandControl& command_control
612 ) = 0;
613
614 virtual RequestZrangebyscore Zrangebyscore(
615 std::string key,
616 double min,
617 double max,
618 const CommandControl& command_control
619 ) = 0;
620
621 virtual RequestZrangebyscore Zrangebyscore(
622 std::string key,
623 std::string min,
624 std::string max,
625 const CommandControl& command_control
626 ) = 0;
627
628 virtual RequestZrangebyscore Zrangebyscore(
629 std::string key,
630 double min,
631 double max,
632 const RangeOptions& range_options,
633 const CommandControl& command_control
634 ) = 0;
635
636 virtual RequestZrangebyscore Zrangebyscore(
637 std::string key,
638 std::string min,
639 std::string max,
640 const RangeOptions& range_options,
641 const CommandControl& command_control
642 ) = 0;
643
644 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
645 std::string key,
646 double min,
647 double max,
648 const CommandControl& command_control
649 ) = 0;
650
651 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
652 std::string key,
653 std::string min,
654 std::string max,
655 const CommandControl& command_control
656 ) = 0;
657
658 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
659 std::string key,
660 double min,
661 double max,
662 const RangeOptions& range_options,
663 const CommandControl& command_control
664 ) = 0;
665
666 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
667 std::string key,
668 std::string min,
669 std::string max,
670 const RangeOptions& range_options,
671 const CommandControl& command_control
672 ) = 0;
673
674 virtual RequestZrem Zrem(std::string key, std::string member, const CommandControl& command_control) = 0;
675
676 virtual RequestZrem Zrem(
677 std::string key,
678 std::vector<std::string> members,
679 const CommandControl& command_control
680 ) = 0;
681
682 virtual RequestZremrangebyrank Zremrangebyrank(
683 std::string key,
684 int64_t start,
685 int64_t stop,
686 const CommandControl& command_control
687 ) = 0;
688
689 virtual RequestZremrangebyscore Zremrangebyscore(
690 std::string key,
691 double min,
692 double max,
693 const CommandControl& command_control
694 ) = 0;
695
696 virtual RequestZremrangebyscore Zremrangebyscore(
697 std::string key,
698 std::string min,
699 std::string max,
700 const CommandControl& command_control
701 ) = 0;
702
703 /// @brief Iterate over a collection of elements.
704 ///
705 /// Sample usage:
706 /// @snippet redis/src/storages/redis/client_scan_redistest.cpp Sample Zscan usage
707 virtual RequestZscan Zscan(std::string key, ZscanOptions options, const CommandControl& command_control) = 0;
708
709 virtual RequestZscore Zscore(std::string key, std::string member, const CommandControl& command_control) = 0;
710
711 // Hash field expiration commands:
712
713 /// @brief Set TTL (in seconds) on one or more hash fields (HEXPIRE).
714 virtual RequestHexpire Hexpire(
715 std::string key,
716 std::chrono::seconds ttl,
717 std::vector<std::string> fields,
718 const CommandControl& command_control
719 ) = 0;
720
721 /// @brief Set TTL (in seconds) on one or more hash fields with NX/XX/GT/LT modifier (HEXPIRE).
722 virtual RequestHexpire Hexpire(
723 std::string key,
724 std::chrono::seconds ttl,
725 ExpireOptions options,
726 std::vector<std::string> fields,
727 const CommandControl& command_control
728 ) = 0;
729
730 /// @brief Set TTL (in milliseconds) on one or more hash fields (HPEXPIRE).
731 virtual RequestHexpire Hpexpire(
732 std::string key,
733 std::chrono::milliseconds ttl,
734 std::vector<std::string> fields,
735 const CommandControl& command_control
736 ) = 0;
737
738 /// @brief Set TTL (in milliseconds) on one or more hash fields with NX/XX/GT/LT modifier (HPEXPIRE).
739 virtual RequestHexpire Hpexpire(
740 std::string key,
741 std::chrono::milliseconds ttl,
742 ExpireOptions options,
743 std::vector<std::string> fields,
744 const CommandControl& command_control
745 ) = 0;
746
747 /// @brief Set absolute expiration deadline on one or more hash fields (HEXPIREAT, seconds-precision).
748 virtual RequestHexpire Hexpireat(
749 std::string key,
750 std::chrono::system_clock::time_point deadline,
751 std::vector<std::string> fields,
752 const CommandControl& command_control
753 ) = 0;
754
755 /// @brief Set absolute expiration deadline on one or more hash fields with modifier (HEXPIREAT).
756 virtual RequestHexpire Hexpireat(
757 std::string key,
758 std::chrono::system_clock::time_point deadline,
759 ExpireOptions options,
760 std::vector<std::string> fields,
761 const CommandControl& command_control
762 ) = 0;
763
764 /// @brief Set absolute expiration deadline on one or more hash fields (HPEXPIREAT, ms-precision).
765 virtual RequestHexpire Hpexpireat(
766 std::string key,
767 std::chrono::system_clock::time_point deadline,
768 std::vector<std::string> fields,
769 const CommandControl& command_control
770 ) = 0;
771
772 /// @brief Set absolute expiration deadline on one or more hash fields with modifier (HPEXPIREAT).
773 virtual RequestHexpire Hpexpireat(
774 std::string key,
775 std::chrono::system_clock::time_point deadline,
776 ExpireOptions options,
777 std::vector<std::string> fields,
778 const CommandControl& command_control
779 ) = 0;
780
781 /// @brief Get absolute expiration unix timestamp (seconds) of one or more hash fields (HEXPIRETIME).
782 virtual RequestHexpiretime Hexpiretime(
783 std::string key,
784 std::vector<std::string> fields,
785 const CommandControl& command_control
786 ) = 0;
787
788 /// @brief Get absolute expiration unix timestamp (ms) of one or more hash fields (HPEXPIRETIME).
789 virtual RequestHpexpiretime Hpexpiretime(
790 std::string key,
791 std::vector<std::string> fields,
792 const CommandControl& command_control
793 ) = 0;
794
795 /// @brief Get remaining TTL (in seconds) of one or more hash fields (HTTL).
796 virtual RequestHttl Httl(
797 std::string key,
798 std::vector<std::string> fields,
799 const CommandControl& command_control
800 ) = 0;
801
802 /// @brief Get remaining TTL (in milliseconds) of one or more hash fields (HPTTL).
803 virtual RequestHpttl Hpttl(
804 std::string key,
805 std::vector<std::string> fields,
806 const CommandControl& command_control
807 ) = 0;
808
809 /// @brief Remove the TTL from one or more hash fields.
810 virtual RequestHpersist Hpersist(
811 std::string key,
812 std::vector<std::string> fields,
813 const CommandControl& command_control
814 ) = 0;
815
816 /// @brief Get the values of one or more hash fields.
817 virtual RequestHgetex Hgetex(
818 std::string key,
819 std::vector<std::string> fields,
820 const CommandControl& command_control
821 ) = 0;
822
823 /// @brief Get the values of one or more hash fields, optionally updating their TTL.
824 virtual RequestHgetex Hgetex(
825 std::string key,
826 HgetexOptions options,
827 std::vector<std::string> fields,
828 const CommandControl& command_control
829 ) = 0;
830
831 /// @brief Set one or more field/value pairs in a hash without a TTL clause.
832 virtual RequestHsetex Hsetex(
833 std::string key,
834 std::vector<HsetexFieldValue> field_values,
835 const CommandControl& command_control
836 ) = 0;
837
838 /// @brief Set one or more field/value pairs in a hash with optional FNX|FXX and TTL modifiers.
839 virtual RequestHsetex Hsetex(
840 std::string key,
841 HsetexOptions options,
842 std::vector<HsetexFieldValue> field_values,
843 const CommandControl& command_control
844 ) = 0;
845
846 // JSON module commands:
847
848 /// @brief Set a JSON value at the given key and path.
849 virtual RequestJsonSet JsonSet(
850 std::string key,
851 std::string path,
852 formats::json::Value value,
853 const CommandControl& command_control
854 ) = 0;
855
856 /// @brief Set a JSON value only if the path does not already exist (NX).
857 virtual RequestJsonSetIfNotExist JsonSetIfNotExist(
858 std::string key,
859 std::string path,
860 formats::json::Value value,
861 const CommandControl& command_control
862 ) = 0;
863
864 /// @brief Set a JSON value only if the path already exists (XX).
865 virtual RequestJsonSetIfExist JsonSetIfExist(
866 std::string key,
867 std::string path,
868 formats::json::Value value,
869 const CommandControl& command_control
870 ) = 0;
871
872 /// @brief Get the JSON value at the root path of the given key.
873 virtual RequestJsonGet JsonGet(std::string key, const CommandControl& command_control) = 0;
874
875 /// @brief Get the JSON value at the given path of the given key.
876 virtual RequestJsonGet JsonGet(std::string key, std::string path, const CommandControl& command_control) = 0;
877
878 /// @brief Get the JSON value at multiple paths of the given key.
879 virtual RequestJsonGet JsonGet(
880 std::string key,
881 std::vector<std::string> paths,
882 const CommandControl& command_control
883 ) = 0;
884
885 /// @brief Get JSON values from multiple keys at the given path.
886 virtual RequestJsonMget JsonMget(
887 std::vector<std::string> keys,
888 std::string path,
889 const CommandControl& command_control
890 ) = 0;
891
892 /// @brief Set JSON values for multiple key-path-value triplets.
893 virtual RequestJsonMset JsonMset(
894 std::vector<JsonKeyPathValue> key_path_values,
895 const CommandControl& command_control
896 ) = 0;
897
898 // end of redis commands
899
900 RequestGet Get(std::string key, RetryNilFromMaster, const CommandControl& command_control);
901
902 RequestHget Hget(std::string key, std::string field, RetryNilFromMaster, const CommandControl& command_control);
903
904 RequestZscore Zscore(
905 std::string key,
906 std::string member,
908 const CommandControl& command_control
909 );
910
911 void Publish(std::string channel, std::string message, const CommandControl& command_control);
912
913 RequestScan Scan(size_t shard, const CommandControl& command_control);
914
915 RequestHscan Hscan(std::string key, const CommandControl& command_control);
916
917 RequestSscan Sscan(std::string key, const CommandControl& command_control);
918
919 RequestZscan Zscan(std::string key, const CommandControl& command_control);
920
921protected:
922 virtual RequestEvalCommon EvalCommon(
923 std::string script,
924 std::vector<std::string> keys,
925 std::vector<std::string> args,
926 const CommandControl& command_control
927 ) = 0;
928 virtual RequestEvalShaCommon EvalShaCommon(
929 std::string script_hash,
930 std::vector<std::string> keys,
931 std::vector<std::string> args,
932 const CommandControl& command_control
933 ) = 0;
934 virtual RequestEvalCommon EvalReadOnlyCommon(
935 std::string script,
936 std::vector<std::string> keys,
937 std::vector<std::string> args,
938 const CommandControl& command_control
939 ) = 0;
940 virtual RequestEvalShaCommon EvalShaReadOnlyCommon(
941 std::string script_hash,
942 std::vector<std::string> keys,
943 std::vector<std::string> args,
944 const CommandControl& command_control
945 ) = 0;
946 virtual RequestGenericCommon GenericCommon(
947 std::string command,
948 std::vector<std::string> args,
949 size_t key_index,
950 const CommandControl& command_control
951 ) = 0;
952};
953
954std::string CreateTmpKey(const std::string& key, std::string prefix);
955
956} // namespace storages::redis
957
958USERVER_NAMESPACE_END