10#include <userver/storages/redis/base.hpp>
11#include <userver/storages/redis/wait_connected_mode.hpp>
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>
22USERVER_NAMESPACE_BEGIN
24namespace storages::
redis {
42 virtual ~Client() =
default;
44 virtual size_t ShardsCount()
const = 0;
45 virtual bool IsInClusterMode()
const = 0;
47 virtual size_t ShardByKey(
const std::string& key)
const = 0;
49 void CheckShardIdx(size_t shard_idx)
const;
55 virtual RequestAppend Append(std::string key, std::string value,
const CommandControl& command_control) = 0;
57 virtual RequestBitop Bitop(
60 std::vector<std::string> src_keys,
64 virtual RequestDbsize Dbsize(size_t shard,
const CommandControl& command_control) = 0;
66 virtual RequestDecr Decr(std::string key,
const CommandControl& command_control) = 0;
68 virtual RequestDel Del(std::string key,
const CommandControl& command_control) = 0;
70 virtual RequestDel Del(std::vector<std::string> keys,
const CommandControl& command_control) = 0;
72 virtual RequestUnlink Unlink(std::string key,
const CommandControl& command_control) = 0;
74 virtual RequestUnlink Unlink(std::vector<std::string> keys,
const CommandControl& command_control) = 0;
82 template <
typename ScriptResult,
typename ReplyType = ScriptResult>
83 RequestEval<ScriptResult, ReplyType> Eval(
85 std::vector<std::string> keys,
86 std::vector<std::string> args,
89 return RequestEval<ScriptResult, ReplyType>{
90 EvalCommon(std::move(script), std::move(keys), std::move(args), command_control)
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,
108 return RequestEvalSha<ScriptResult, ReplyType>{
109 EvalShaCommon(std::move(script_hash), std::move(keys), std::move(args), command_control)
119 template <
typename ScriptResult,
typename ReplyType = ScriptResult>
120 RequestEval<ScriptResult, ReplyType> EvalReadOnly(
122 std::vector<std::string> keys,
123 std::vector<std::string> args,
126 return RequestEval<ScriptResult, ReplyType>{
127 EvalReadOnlyCommon(std::move(script), std::move(keys), std::move(args), command_control)
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,
144 return RequestEvalSha<ScriptResult, ReplyType>{
145 EvalShaReadOnlyCommon(std::move(script_hash), std::move(keys), std::move(args), command_control)
154 template <
typename ReplyType>
155 RequestGeneric<ReplyType> GenericCommand(
157 std::vector<std::string> args,
161 return RequestGeneric<ReplyType>{GenericCommon(std::move(command), std::move(args), key_index, command_control)
169 virtual RequestScriptLoad ScriptLoad(std::string script, size_t shard,
const CommandControl& command_control) = 0;
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,
179 return RequestEval<std::decay_t<ScriptInfo>, ReplyType>{
180 EvalCommon(script_info.GetScript(), std::move(keys), std::move(args), command_control)
184 virtual RequestExists Exists(std::string key,
const CommandControl& command_control) = 0;
186 virtual RequestExists Exists(std::vector<std::string> keys,
const CommandControl& command_control) = 0;
188 virtual RequestExpire Expire(std::string key, std::chrono::seconds ttl,
const CommandControl& command_control) = 0;
190 virtual RequestExpire Expire(
192 std::chrono::seconds ttl,
197 virtual RequestGeoadd Geoadd(std::string key,
GeoaddArg point_member,
const CommandControl& command_control) = 0;
199 virtual RequestGeoadd Geoadd(
205 virtual RequestGeopos Geopos(
207 std::vector<std::string> members,
211 virtual RequestGeoradius Georadius(
220 virtual RequestGeosearch Geosearch(
228 virtual RequestGeosearch Geosearch(
237 virtual RequestGeosearch Geosearch(
246 virtual RequestGeosearch Geosearch(
256 virtual RequestGet Get(std::string key,
const CommandControl& command_control) = 0;
258 virtual RequestGetset Getset(std::string key, std::string value,
const CommandControl& command_control) = 0;
260 virtual RequestHdel Hdel(std::string key, std::string field,
const CommandControl& command_control) = 0;
262 virtual RequestHdel Hdel(
264 std::vector<std::string> fields,
268 virtual RequestHexists Hexists(std::string key, std::string field,
const CommandControl& command_control) = 0;
270 virtual RequestHget Hget(std::string key, std::string field,
const CommandControl& command_control) = 0;
273 virtual RequestHgetall Hgetall(std::string key,
const CommandControl& command_control) = 0;
275 virtual RequestHincrby Hincrby(
282 virtual RequestHincrbyfloat Hincrbyfloat(
290 virtual RequestHkeys Hkeys(std::string key,
const CommandControl& command_control) = 0;
292 virtual RequestHlen Hlen(std::string key,
const CommandControl& command_control) = 0;
294 virtual RequestHmget Hmget(
296 std::vector<std::string> fields,
300 virtual RequestHmset Hmset(
302 std::vector<std::pair<std::string, std::string>> field_values,
310 virtual RequestHscan Hscan(std::string key, HscanOptions options,
const CommandControl& command_control) = 0;
312 virtual RequestHset Hset(
319 virtual RequestHsetnx Hsetnx(
327 virtual RequestHvals Hvals(std::string key,
const CommandControl& command_control) = 0;
329 virtual RequestIncr Incr(std::string key,
const CommandControl& command_control) = 0;
331 [[deprecated(
"use Scan")]]
virtual RequestKeys Keys(
332 std::string keys_pattern,
337 virtual RequestLindex Lindex(std::string key, int64_t index,
const CommandControl& command_control) = 0;
339 virtual RequestLlen Llen(std::string key,
const CommandControl& command_control) = 0;
341 virtual RequestLpop Lpop(std::string key,
const CommandControl& command_control) = 0;
343 virtual RequestLpush Lpush(std::string key, std::string value,
const CommandControl& command_control) = 0;
345 virtual RequestLpush Lpush(
347 std::vector<std::string> values,
351 virtual RequestLpushx Lpushx(std::string key, std::string element,
const CommandControl& command_control) = 0;
353 virtual RequestLrange Lrange(
360 virtual RequestLrem Lrem(
367 virtual RequestLtrim Ltrim(std::string key, int64_t start, int64_t stop,
const CommandControl& command_control) = 0;
369 virtual RequestMget Mget(std::vector<std::string> keys,
const CommandControl& command_control) = 0;
371 virtual RequestMset Mset(
372 std::vector<std::pair<std::string, std::string>> key_values,
376 virtual TransactionPtr Multi() = 0;
378 virtual TransactionPtr Multi(
Transaction::CheckShards check_shards) = 0;
380 virtual RequestPersist Persist(std::string key,
const CommandControl& command_control) = 0;
382 virtual RequestPexpire Pexpire(
384 std::chrono::milliseconds ttl,
388 virtual RequestPing Ping(size_t shard,
const CommandControl& command_control) = 0;
390 virtual RequestPingMessage Ping(size_t shard, std::string message,
const CommandControl& command_control) = 0;
392 virtual void Publish(
399 virtual void Spublish(std::string channel, std::string message,
const CommandControl& command_control) = 0;
401 virtual RequestRename Rename(std::string key, std::string new_key,
const CommandControl& command_control) = 0;
403 virtual RequestRpop Rpop(std::string key,
const CommandControl& command_control) = 0;
405 virtual RequestRpush Rpush(std::string key, std::string value,
const CommandControl& command_control) = 0;
407 virtual RequestRpush Rpush(
409 std::vector<std::string> values,
413 virtual RequestRpushx Rpushx(std::string key, std::string element,
const CommandControl& command_control) = 0;
419 virtual RequestSadd Sadd(std::string key, std::string member,
const CommandControl& command_control) = 0;
422 virtual RequestSadd Sadd(
424 std::vector<std::string> members,
432 virtual RequestScan Scan(size_t shard, ScanOptions options,
const CommandControl& command_control) = 0;
434 virtual RequestScard Scard(std::string key,
const CommandControl& command_control) = 0;
436 virtual RequestSet Set(std::string key, std::string value,
const CommandControl& command_control) = 0;
438 virtual RequestSet Set(
441 std::chrono::milliseconds ttl,
445 virtual RequestSetIfExist SetIfExist(std::string key, std::string value,
const CommandControl& command_control) = 0;
447 virtual RequestSetIfExist SetIfExist(
450 std::chrono::milliseconds ttl,
454 virtual RequestSetIfNotExist SetIfNotExist(
460 virtual RequestSetIfNotExist SetIfNotExist(
463 std::chrono::milliseconds ttl,
467 virtual RequestSetIfNotExistOrGet SetIfNotExistOrGet(
473 virtual RequestSetIfNotExistOrGet SetIfNotExistOrGet(
476 std::chrono::milliseconds ttl,
480 virtual RequestSetex Setex(
482 std::chrono::seconds seconds,
487 virtual RequestSetAndGetPrevious SetAndGetPrevious(
490 std::chrono::milliseconds ttl,
494 virtual RequestSismember Sismember(std::string key, std::string member,
const CommandControl& command_control) = 0;
497 virtual RequestSmembers Smembers(std::string key,
const CommandControl& command_control) = 0;
499 virtual RequestSrandmember Srandmember(std::string key,
const CommandControl& command_control) = 0;
501 virtual RequestSrandmembers Srandmembers(std::string key, int64_t count,
const CommandControl& command_control) = 0;
503 virtual RequestSrem Srem(std::string key, std::string member,
const CommandControl& command_control) = 0;
505 virtual RequestSrem Srem(
507 std::vector<std::string> members,
515 virtual RequestSscan Sscan(std::string key, SscanOptions options,
const CommandControl& command_control) = 0;
517 virtual RequestStrlen Strlen(std::string key,
const CommandControl& command_control) = 0;
519 virtual RequestTime Time(size_t shard,
const CommandControl& command_control) = 0;
521 virtual RequestTtl Ttl(std::string key,
const CommandControl& command_control) = 0;
523 virtual RequestType Type(std::string key,
const CommandControl& command_control) = 0;
525 virtual RequestZadd Zadd(
532 virtual RequestZadd Zadd(
540 virtual RequestZadd Zadd(
542 std::vector<std::pair<
double, std::string>> scored_members,
546 virtual RequestZadd Zadd(
548 std::vector<std::pair<
double, std::string>> scored_members,
553 virtual RequestZaddIncr ZaddIncr(
560 virtual RequestZaddIncrExisting ZaddIncrExisting(
567 virtual RequestZcard Zcard(std::string key,
const CommandControl& command_control) = 0;
569 virtual RequestZcount Zcount(std::string key,
double min,
double max,
const CommandControl& command_control) = 0;
571 virtual RequestZrange Zrange(
578 virtual RequestZrangeWithScores ZrangeWithScores(
585 virtual RequestZrangebyscore Zrangebyscore(
592 virtual RequestZrangebyscore Zrangebyscore(
599 virtual RequestZrangebyscore Zrangebyscore(
607 virtual RequestZrangebyscore Zrangebyscore(
615 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
622 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
629 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
637 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
645 virtual RequestZrem Zrem(std::string key, std::string member,
const CommandControl& command_control) = 0;
647 virtual RequestZrem Zrem(
649 std::vector<std::string> members,
653 virtual RequestZremrangebyrank Zremrangebyrank(
660 virtual RequestZremrangebyscore Zremrangebyscore(
667 virtual RequestZremrangebyscore Zremrangebyscore(
678 virtual RequestZscan Zscan(std::string key, ZscanOptions options,
const CommandControl& command_control) = 0;
680 virtual RequestZscore Zscore(std::string key, std::string member,
const CommandControl& command_control) = 0;
685 virtual RequestHexpire Hexpire(
687 std::chrono::seconds ttl,
688 std::vector<std::string> fields,
693 virtual RequestHexpire Hexpire(
695 std::chrono::seconds ttl,
697 std::vector<std::string> fields,
702 virtual RequestHexpire Hpexpire(
704 std::chrono::milliseconds ttl,
705 std::vector<std::string> fields,
710 virtual RequestHexpire Hpexpire(
712 std::chrono::milliseconds ttl,
714 std::vector<std::string> fields,
719 virtual RequestHexpire Hexpireat(
721 std::chrono::system_clock::time_point deadline,
722 std::vector<std::string> fields,
727 virtual RequestHexpire Hexpireat(
729 std::chrono::system_clock::time_point deadline,
731 std::vector<std::string> fields,
736 virtual RequestHexpire Hpexpireat(
738 std::chrono::system_clock::time_point deadline,
739 std::vector<std::string> fields,
744 virtual RequestHexpire Hpexpireat(
746 std::chrono::system_clock::time_point deadline,
748 std::vector<std::string> fields,
753 virtual RequestHexpiretime Hexpiretime(
755 std::vector<std::string> fields,
760 virtual RequestHpexpiretime Hpexpiretime(
762 std::vector<std::string> fields,
767 virtual RequestHttl Httl(
769 std::vector<std::string> fields,
774 virtual RequestHpttl Hpttl(
776 std::vector<std::string> fields,
781 virtual RequestHpersist Hpersist(
783 std::vector<std::string> fields,
788 virtual RequestHgetex Hgetex(
790 std::vector<std::string> fields,
795 virtual RequestHgetex Hgetex(
798 std::vector<std::string> fields,
803 virtual RequestHsetex Hsetex(
810 virtual RequestHsetex Hsetex(
820 virtual RequestJsonSet JsonSet(
828 virtual RequestJsonSetIfNotExist JsonSetIfNotExist(
836 virtual RequestJsonSetIfExist JsonSetIfExist(
844 virtual RequestJsonGet JsonGet(std::string key,
const CommandControl& command_control) = 0;
847 virtual RequestJsonGet JsonGet(std::string key, std::string path,
const CommandControl& command_control) = 0;
850 virtual RequestJsonGet JsonGet(
852 std::vector<std::string> paths,
857 virtual RequestJsonMget JsonMget(
858 std::vector<std::string> keys,
864 virtual RequestJsonMset JsonMset(
865 std::vector<JsonKeyPathValue> key_path_values,
875 RequestZscore Zscore(
882 void Publish(std::string channel, std::string message,
const CommandControl& command_control);
884 RequestScan Scan(size_t shard,
const CommandControl& command_control);
886 RequestHscan Hscan(std::string key,
const CommandControl& command_control);
888 RequestSscan Sscan(std::string key,
const CommandControl& command_control);
890 RequestZscan Zscan(std::string key,
const CommandControl& command_control);
893 virtual RequestEvalCommon EvalCommon(
895 std::vector<std::string> keys,
896 std::vector<std::string> args,
899 virtual RequestEvalShaCommon EvalShaCommon(
900 std::string script_hash,
901 std::vector<std::string> keys,
902 std::vector<std::string> args,
905 virtual RequestEvalCommon EvalReadOnlyCommon(
907 std::vector<std::string> keys,
908 std::vector<std::string> args,
911 virtual RequestEvalShaCommon EvalShaReadOnlyCommon(
912 std::string script_hash,
913 std::vector<std::string> keys,
914 std::vector<std::string> args,
917 virtual RequestGenericCommon GenericCommon(
919 std::vector<std::string> args,
925std::string CreateTmpKey(
const std::string& key, std::string prefix);