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