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