10#include <userver/storages/redis/impl/base.hpp> 
   11#include <userver/storages/redis/impl/wait_connected_mode.hpp> 
   13#include <userver/storages/redis/client_fwd.hpp> 
   14#include <userver/storages/redis/command_options.hpp> 
   15#include <userver/storages/redis/request.hpp> 
   16#include <userver/storages/redis/request_eval.hpp> 
   17#include <userver/storages/redis/request_evalsha.hpp> 
   18#include <userver/storages/redis/transaction.hpp> 
   20USERVER_NAMESPACE_BEGIN
 
   31inline constexpr RetryNilFromMaster kRetryNilFromMaster{};
 
   44  virtual ~Client() = 
default;
 
   46  virtual size_t ShardsCount() 
const = 0;
 
   47  virtual bool IsInClusterMode() 
const = 0;
 
   49  virtual size_t ShardByKey(
const std::string& key) 
const = 0;
 
   51  void CheckShardIdx(size_t shard_idx) 
const;
 
   53  virtual const std::string& GetAnyKeyForShard(size_t shard_idx) 
const = 0;
 
   55  virtual std::shared_ptr<
Client> GetClientForShard(size_t shard_idx) = 0;
 
   57  virtual void WaitConnectedOnce(
 
   62  virtual RequestAppend Append(std::string key, std::string value,
 
   63                               const CommandControl& command_control) = 0;
 
   65  virtual RequestDbsize Dbsize(size_t shard,
 
   66                               const CommandControl& command_control) = 0;
 
   68  virtual RequestDel Del(std::string key,
 
   69                         const CommandControl& command_control) = 0;
 
   71  virtual RequestDel Del(std::vector<std::string> keys,
 
   72                         const CommandControl& command_control) = 0;
 
   74  virtual RequestUnlink Unlink(std::string key,
 
   75                               const CommandControl& command_control) = 0;
 
   77  virtual RequestUnlink Unlink(std::vector<std::string> keys,
 
   78                               const CommandControl& command_control) = 0;
 
   80  template <
typename ScriptResult, 
typename ReplyType = ScriptResult>
 
   81  RequestEval<ScriptResult, ReplyType> Eval(
 
   82      std::string script, std::vector<std::string> keys,
 
   83      std::vector<std::string> args, 
const CommandControl& command_control) {
 
   84    return RequestEval<ScriptResult, ReplyType>{EvalCommon(
 
   85        std::move(script), std::move(keys), std::move(args), command_control)};
 
   87  template <
typename ScriptResult, 
typename ReplyType = ScriptResult>
 
   88  RequestEvalSha<ScriptResult, ReplyType> EvalSha(
 
   89      std::string script_hash, std::vector<std::string> keys,
 
   90      std::vector<std::string> args, 
const CommandControl& command_control) {
 
   91    return RequestEvalSha<ScriptResult, ReplyType>{
 
   92        EvalShaCommon(std::move(script_hash), std::move(keys), std::move(args),
 
   96  virtual RequestScriptLoad ScriptLoad(
 
   97      std::string script, size_t shard,
 
   98      const CommandControl& command_control) = 0;
 
  100  template <
typename ScriptInfo, 
typename ReplyType = std::decay_t<ScriptInfo>>
 
  101  RequestEval<std::decay_t<ScriptInfo>, ReplyType> Eval(
 
  102      const ScriptInfo& script_info, std::vector<std::string> keys,
 
  103      std::vector<std::string> args, 
const CommandControl& command_control) {
 
  104    return RequestEval<std::decay_t<ScriptInfo>, ReplyType>{
 
  105        EvalCommon(script_info.GetScript(), std::move(keys), std::move(args),
 
  109  virtual RequestExists Exists(std::string key,
 
  110                               const CommandControl& command_control) = 0;
 
  112  virtual RequestExists Exists(std::vector<std::string> keys,
 
  113                               const CommandControl& command_control) = 0;
 
  115  virtual RequestExpire Expire(std::string key, std::chrono::seconds ttl,
 
  116                               const CommandControl& command_control) = 0;
 
  118  virtual RequestGeoadd Geoadd(std::string key, GeoaddArg point_member,
 
  119                               const CommandControl& command_control) = 0;
 
  121  virtual RequestGeoadd Geoadd(std::string key,
 
  122                               std::vector<GeoaddArg> point_members,
 
  123                               const CommandControl& command_control) = 0;
 
  125  virtual RequestGeoradius Georadius(std::string key, Longitude lon,
 
  126                                     Latitude lat, 
double radius,
 
  127                                     const GeoradiusOptions& georadius_options,
 
  128                                     const CommandControl& command_control) = 0;
 
  130  virtual RequestGeosearch Geosearch(std::string key, std::string member,
 
  132                                     const GeosearchOptions& geosearch_options,
 
  133                                     const CommandControl& command_control) = 0;
 
  135  virtual RequestGeosearch Geosearch(std::string key, std::string member,
 
  136                                     BoxWidth width, BoxHeight height,
 
  137                                     const GeosearchOptions& geosearch_options,
 
  138                                     const CommandControl& command_control) = 0;
 
  140  virtual RequestGeosearch Geosearch(std::string key, Longitude lon,
 
  141                                     Latitude lat, 
double radius,
 
  142                                     const GeosearchOptions& geosearch_options,
 
  143                                     const CommandControl& command_control) = 0;
 
  145  virtual RequestGeosearch Geosearch(std::string key, Longitude lon,
 
  146                                     Latitude lat, BoxWidth width,
 
  148                                     const GeosearchOptions& geosearch_options,
 
  149                                     const CommandControl& command_control) = 0;
 
  151  virtual RequestGet Get(std::string key,
 
  152                         const CommandControl& command_control) = 0;
 
  154  virtual RequestGetset Getset(std::string key, std::string value,
 
  155                               const CommandControl& command_control) = 0;
 
  157  virtual RequestHdel Hdel(std::string key, std::string field,
 
  158                           const CommandControl& command_control) = 0;
 
  160  virtual RequestHdel Hdel(std::string key, std::vector<std::string> fields,
 
  161                           const CommandControl& command_control) = 0;
 
  163  virtual RequestHexists Hexists(std::string key, std::string field,
 
  164                                 const CommandControl& command_control) = 0;
 
  166  virtual RequestHget Hget(std::string key, std::string field,
 
  167                           const CommandControl& command_control) = 0;
 
  170  virtual RequestHgetall Hgetall(std::string key,
 
  171                                 const CommandControl& command_control) = 0;
 
  173  virtual RequestHincrby Hincrby(std::string key, std::string field,
 
  175                                 const CommandControl& command_control) = 0;
 
  177  virtual RequestHincrbyfloat Hincrbyfloat(
 
  178      std::string key, std::string field, 
double increment,
 
  179      const CommandControl& command_control) = 0;
 
  182  virtual RequestHkeys Hkeys(std::string key,
 
  183                             const CommandControl& command_control) = 0;
 
  185  virtual RequestHlen Hlen(std::string key,
 
  186                           const CommandControl& command_control) = 0;
 
  188  virtual RequestHmget Hmget(std::string key, std::vector<std::string> fields,
 
  189                             const CommandControl& command_control) = 0;
 
  191  virtual RequestHmset Hmset(
 
  193      std::vector<std::pair<std::string, std::string>> field_values,
 
  194      const CommandControl& command_control) = 0;
 
  196  virtual RequestHscan Hscan(std::string key, HscanOptions options,
 
  197                             const CommandControl& command_control) = 0;
 
  199  virtual RequestHset Hset(std::string key, std::string field,
 
  201                           const CommandControl& command_control) = 0;
 
  203  virtual RequestHsetnx Hsetnx(std::string key, std::string field,
 
  205                               const CommandControl& command_control) = 0;
 
  208  virtual RequestHvals Hvals(std::string key,
 
  209                             const CommandControl& command_control) = 0;
 
  211  virtual RequestIncr Incr(std::string key,
 
  212                           const CommandControl& command_control) = 0;
 
  214  [[
deprecated(
"use Scan")]] 
virtual RequestKeys Keys(
 
  215      std::string keys_pattern, size_t shard,
 
  216      const CommandControl& command_control) = 0;
 
  218  virtual RequestLindex Lindex(std::string key, int64_t index,
 
  219                               const CommandControl& command_control) = 0;
 
  221  virtual RequestLlen Llen(std::string key,
 
  222                           const CommandControl& command_control) = 0;
 
  224  virtual RequestLpop Lpop(std::string key,
 
  225                           const CommandControl& command_control) = 0;
 
  227  virtual RequestLpush Lpush(std::string key, std::string value,
 
  228                             const CommandControl& command_control) = 0;
 
  230  virtual RequestLpush Lpush(std::string key, std::vector<std::string> values,
 
  231                             const CommandControl& command_control) = 0;
 
  233  virtual RequestLpushx Lpushx(std::string key, std::string element,
 
  234                               const CommandControl& command_control) = 0;
 
  236  virtual RequestLrange Lrange(std::string key, int64_t start, int64_t stop,
 
  237                               const CommandControl& command_control) = 0;
 
  239  virtual RequestLrem Lrem(std::string key, int64_t count, std::string element,
 
  240                           const CommandControl& command_control) = 0;
 
  242  virtual RequestLtrim Ltrim(std::string key, int64_t start, int64_t stop,
 
  243                             const CommandControl& command_control) = 0;
 
  245  virtual RequestMget Mget(std::vector<std::string> keys,
 
  246                           const CommandControl& command_control) = 0;
 
  248  virtual RequestMset Mset(
 
  249      std::vector<std::pair<std::string, std::string>> key_values,
 
  250      const CommandControl& command_control) = 0;
 
  252  virtual TransactionPtr Multi() = 0;
 
  254  virtual TransactionPtr Multi(Transaction::CheckShards check_shards) = 0;
 
  256  virtual RequestPersist Persist(std::string key,
 
  257                                 const CommandControl& command_control) = 0;
 
  259  virtual RequestPexpire Pexpire(std::string key, std::chrono::milliseconds ttl,
 
  260                                 const CommandControl& command_control) = 0;
 
  262  virtual RequestPing Ping(size_t shard,
 
  263                           const CommandControl& command_control) = 0;
 
  265  virtual RequestPingMessage Ping(size_t shard, std::string message,
 
  266                                  const CommandControl& command_control) = 0;
 
  268  virtual void Publish(std::string channel, std::string message,
 
  269                       const CommandControl& command_control,
 
  270                       PubShard policy) = 0;
 
  272  virtual void Spublish(std::string channel, std::string message,
 
  273                        const CommandControl& command_control) = 0;
 
  275  virtual RequestRename Rename(std::string key, std::string new_key,
 
  276                               const CommandControl& command_control) = 0;
 
  278  virtual RequestRpop Rpop(std::string key,
 
  279                           const CommandControl& command_control) = 0;
 
  281  virtual RequestRpush Rpush(std::string key, std::string value,
 
  282                             const CommandControl& command_control) = 0;
 
  284  virtual RequestRpush Rpush(std::string key, std::vector<std::string> values,
 
  285                             const CommandControl& command_control) = 0;
 
  287  virtual RequestRpushx Rpushx(std::string key, std::string element,
 
  288                               const CommandControl& command_control) = 0;
 
  290  virtual RequestSadd Sadd(std::string key, std::string member,
 
  291                           const CommandControl& command_control) = 0;
 
  293  virtual RequestSadd Sadd(std::string key, std::vector<std::string> members,
 
  294                           const CommandControl& command_control) = 0;
 
  296  virtual RequestScan Scan(size_t shard, ScanOptions options,
 
  297                           const CommandControl& command_control) = 0;
 
  299  virtual RequestScard Scard(std::string key,
 
  300                             const CommandControl& command_control) = 0;
 
  302  virtual RequestSet Set(std::string key, std::string value,
 
  303                         const CommandControl& command_control) = 0;
 
  305  virtual RequestSet Set(std::string key, std::string value,
 
  306                         std::chrono::milliseconds ttl,
 
  307                         const CommandControl& command_control) = 0;
 
  309  virtual RequestSetIfExist SetIfExist(
 
  310      std::string key, std::string value,
 
  311      const CommandControl& command_control) = 0;
 
  313  virtual RequestSetIfExist SetIfExist(
 
  314      std::string key, std::string value, std::chrono::milliseconds ttl,
 
  315      const CommandControl& command_control) = 0;
 
  317  virtual RequestSetIfNotExist SetIfNotExist(
 
  318      std::string key, std::string value,
 
  319      const CommandControl& command_control) = 0;
 
  321  virtual RequestSetIfNotExist SetIfNotExist(
 
  322      std::string key, std::string value, std::chrono::milliseconds ttl,
 
  323      const CommandControl& command_control) = 0;
 
  325  virtual RequestSetex Setex(std::string key, std::chrono::seconds seconds,
 
  327                             const CommandControl& command_control) = 0;
 
  329  virtual RequestSismember Sismember(std::string key, std::string member,
 
  330                                     const CommandControl& command_control) = 0;
 
  333  virtual RequestSmembers Smembers(std::string key,
 
  334                                   const CommandControl& command_control) = 0;
 
  336  virtual RequestSrandmember Srandmember(
 
  337      std::string key, 
const CommandControl& command_control) = 0;
 
  339  virtual RequestSrandmembers Srandmembers(
 
  340      std::string key, int64_t count,
 
  341      const CommandControl& command_control) = 0;
 
  343  virtual RequestSrem Srem(std::string key, std::string member,
 
  344                           const CommandControl& command_control) = 0;
 
  346  virtual RequestSrem Srem(std::string key, std::vector<std::string> members,
 
  347                           const CommandControl& command_control) = 0;
 
  349  virtual RequestSscan Sscan(std::string key, SscanOptions options,
 
  350                             const CommandControl& command_control) = 0;
 
  352  virtual RequestStrlen Strlen(std::string key,
 
  353                               const CommandControl& command_control) = 0;
 
  355  virtual RequestTime Time(size_t shard,
 
  356                           const CommandControl& command_control) = 0;
 
  358  virtual RequestTtl Ttl(std::string key,
 
  359                         const CommandControl& command_control) = 0;
 
  361  virtual RequestType Type(std::string key,
 
  362                           const CommandControl& command_control) = 0;
 
  364  virtual RequestZadd Zadd(std::string key, 
double score, std::string member,
 
  365                           const CommandControl& command_control) = 0;
 
  367  virtual RequestZadd Zadd(std::string key, 
double score, std::string member,
 
  368                           const ZaddOptions& options,
 
  369                           const CommandControl& command_control) = 0;
 
  371  virtual RequestZadd Zadd(
 
  373      std::vector<std::pair<
double, std::string>> scored_members,
 
  374      const CommandControl& command_control) = 0;
 
  376  virtual RequestZadd Zadd(
 
  378      std::vector<std::pair<
double, std::string>> scored_members,
 
  379      const ZaddOptions& options, 
const CommandControl& command_control) = 0;
 
  381  virtual RequestZaddIncr ZaddIncr(std::string key, 
double score,
 
  383                                   const CommandControl& command_control) = 0;
 
  385  virtual RequestZaddIncrExisting ZaddIncrExisting(
 
  386      std::string key, 
double score, std::string member,
 
  387      const CommandControl& command_control) = 0;
 
  389  virtual RequestZcard Zcard(std::string key,
 
  390                             const CommandControl& command_control) = 0;
 
  392  virtual RequestZcount Zcount(std::string key, 
double min, 
double max,
 
  393                               const CommandControl& command_control) = 0;
 
  395  virtual RequestZrange Zrange(std::string key, int64_t start, int64_t stop,
 
  396                               const CommandControl& command_control) = 0;
 
  398  virtual RequestZrangeWithScores ZrangeWithScores(
 
  399      std::string key, int64_t start, int64_t stop,
 
  400      const CommandControl& command_control) = 0;
 
  402  virtual RequestZrangebyscore Zrangebyscore(
 
  403      std::string key, 
double min, 
double max,
 
  404      const CommandControl& command_control) = 0;
 
  406  virtual RequestZrangebyscore Zrangebyscore(
 
  407      std::string key, std::string min, std::string max,
 
  408      const CommandControl& command_control) = 0;
 
  410  virtual RequestZrangebyscore Zrangebyscore(
 
  411      std::string key, 
double min, 
double max,
 
  412      const RangeOptions& range_options,
 
  413      const CommandControl& command_control) = 0;
 
  415  virtual RequestZrangebyscore Zrangebyscore(
 
  416      std::string key, std::string min, std::string max,
 
  417      const RangeOptions& range_options,
 
  418      const CommandControl& command_control) = 0;
 
  420  virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
 
  421      std::string key, 
double min, 
double max,
 
  422      const CommandControl& command_control) = 0;
 
  424  virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
 
  425      std::string key, std::string min, std::string max,
 
  426      const CommandControl& command_control) = 0;
 
  428  virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
 
  429      std::string key, 
double min, 
double max,
 
  430      const RangeOptions& range_options,
 
  431      const CommandControl& command_control) = 0;
 
  433  virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
 
  434      std::string key, std::string min, std::string max,
 
  435      const RangeOptions& range_options,
 
  436      const CommandControl& command_control) = 0;
 
  438  virtual RequestZrem Zrem(std::string key, std::string member,
 
  439                           const CommandControl& command_control) = 0;
 
  441  virtual RequestZrem Zrem(std::string key, std::vector<std::string> members,
 
  442                           const CommandControl& command_control) = 0;
 
  444  virtual RequestZremrangebyrank Zremrangebyrank(
 
  445      std::string key, int64_t start, int64_t stop,
 
  446      const CommandControl& command_control) = 0;
 
  448  virtual RequestZremrangebyscore Zremrangebyscore(
 
  449      std::string key, 
double min, 
double max,
 
  450      const CommandControl& command_control) = 0;
 
  452  virtual RequestZremrangebyscore Zremrangebyscore(
 
  453      std::string key, std::string min, std::string max,
 
  454      const CommandControl& command_control) = 0;
 
  456  virtual RequestZscan Zscan(std::string key, ZscanOptions options,
 
  457                             const CommandControl& command_control) = 0;
 
  459  virtual RequestZscore Zscore(std::string key, std::string member,
 
  460                               const CommandControl& command_control) = 0;
 
  464  RequestGet Get(std::string key, RetryNilFromMaster,
 
  465                 const CommandControl& command_control);
 
  467  RequestHget Hget(std::string key, std::string field, RetryNilFromMaster,
 
  468                   const CommandControl& command_control);
 
  470  RequestZscore Zscore(std::string key, std::string member, RetryNilFromMaster,
 
  471                       const CommandControl& command_control);
 
  473  void Publish(std::string channel, std::string message,
 
  474               const CommandControl& command_control);
 
  476  RequestScan Scan(size_t shard, 
const CommandControl& command_control);
 
  478  RequestHscan Hscan(std::string key, 
const CommandControl& command_control);
 
  480  RequestSscan Sscan(std::string key, 
const CommandControl& command_control);
 
  482  RequestZscan Zscan(std::string key, 
const CommandControl& command_control);
 
  485  virtual RequestEvalCommon EvalCommon(
 
  486      std::string script, std::vector<std::string> keys,
 
  487      std::vector<std::string> args, 
const CommandControl& command_control) = 0;
 
  488  virtual RequestEvalShaCommon EvalShaCommon(
 
  489      std::string script_hash, std::vector<std::string> keys,
 
  490      std::vector<std::string> args, 
const CommandControl& command_control) = 0;
 
  493std::string CreateTmpKey(
const std::string& key, std::string prefix);