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