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)};
100 template <
typename ScriptResult,
typename ReplyType = ScriptResult>
101 RequestEvalSha<ScriptResult, ReplyType>
EvalSha(
102 std::string script_hash,
103 std::vector<std::string> keys,
104 std::vector<std::string> args,
107 return RequestEvalSha<ScriptResult, ReplyType>{
108 EvalShaCommon(std::move(script_hash), std::move(keys), std::move(args), command_control)};
116 template <
typename ReplyType>
119 std::vector<std::string> args,
123 return RequestGeneric<ReplyType>{
124 GenericCommon(std::move(command), std::move(args), key_index, command_control)};
134 template <
typename ScriptInfo,
typename ReplyType = std::decay_t<ScriptInfo>>
135 RequestEval<std::decay_t<ScriptInfo>, ReplyType>
Eval(
136 const ScriptInfo& script_info,
137 std::vector<std::string> keys,
138 std::vector<std::string> args,
141 return RequestEval<std::decay_t<ScriptInfo>, ReplyType>{
142 EvalCommon(script_info.GetScript(), std::move(keys), std::move(args), command_control)};
145 virtual RequestExists Exists(std::string key,
const CommandControl& command_control) = 0;
147 virtual RequestExists Exists(std::vector<std::string> keys,
const CommandControl& command_control) = 0;
149 virtual RequestExpire Expire(std::string key, std::chrono::seconds ttl,
const CommandControl& command_control) = 0;
151 virtual RequestExpire
154 virtual RequestGeoadd Geoadd(std::string key,
GeoaddArg point_member,
const CommandControl& command_control) = 0;
156 virtual RequestGeoadd
159 virtual RequestGeopos
160 Geopos(std::string key, std::vector<std::string> members,
const CommandControl& command_control) = 0;
162 virtual RequestGeoradius Georadius(
171 virtual RequestGeosearch Geosearch(
179 virtual RequestGeosearch Geosearch(
188 virtual RequestGeosearch Geosearch(
197 virtual RequestGeosearch Geosearch(
207 virtual RequestGet Get(std::string key,
const CommandControl& command_control) = 0;
209 virtual RequestGetset Getset(std::string key, std::string value,
const CommandControl& command_control) = 0;
211 virtual RequestHdel Hdel(std::string key, std::string field,
const CommandControl& command_control) = 0;
214 Hdel(std::string key, std::vector<std::string> fields,
const CommandControl& command_control) = 0;
216 virtual RequestHexists Hexists(std::string key, std::string field,
const CommandControl& command_control) = 0;
218 virtual RequestHget Hget(std::string key, std::string field,
const CommandControl& command_control) = 0;
221 virtual RequestHgetall Hgetall(std::string key,
const CommandControl& command_control) = 0;
223 virtual RequestHincrby
224 Hincrby(std::string key, std::string field, int64_t increment,
const CommandControl& command_control) = 0;
226 virtual RequestHincrbyfloat
227 Hincrbyfloat(std::string key, std::string field,
double increment,
const CommandControl& command_control) = 0;
230 virtual RequestHkeys Hkeys(std::string key,
const CommandControl& command_control) = 0;
232 virtual RequestHlen Hlen(std::string key,
const CommandControl& command_control) = 0;
235 Hmget(std::string key, std::vector<std::string> fields,
const CommandControl& command_control) = 0;
237 virtual RequestHmset Hmset(
239 std::vector<std::pair<std::string, std::string>> field_values,
247 virtual RequestHscan
Hscan(std::string key, HscanOptions options,
const CommandControl& command_control) = 0;
250 Hset(std::string key, std::string field, std::string value,
const CommandControl& command_control) = 0;
252 virtual RequestHsetnx
253 Hsetnx(std::string key, std::string field, std::string value,
const CommandControl& command_control) = 0;
256 virtual RequestHvals Hvals(std::string key,
const CommandControl& command_control) = 0;
258 virtual RequestIncr Incr(std::string key,
const CommandControl& command_control) = 0;
260 [[
deprecated(
"use Scan")]]
virtual RequestKeys
261 Keys(std::string keys_pattern, size_t shard,
const CommandControl& command_control) = 0;
263 virtual RequestLindex Lindex(std::string key, int64_t index,
const CommandControl& command_control) = 0;
265 virtual RequestLlen Llen(std::string key,
const CommandControl& command_control) = 0;
267 virtual RequestLpop Lpop(std::string key,
const CommandControl& command_control) = 0;
269 virtual RequestLpush Lpush(std::string key, std::string value,
const CommandControl& command_control) = 0;
272 Lpush(std::string key, std::vector<std::string> values,
const CommandControl& command_control) = 0;
274 virtual RequestLpushx Lpushx(std::string key, std::string element,
const CommandControl& command_control) = 0;
276 virtual RequestLrange
277 Lrange(std::string key, int64_t start, int64_t stop,
const CommandControl& command_control) = 0;
280 Lrem(std::string key, int64_t count, std::string element,
const CommandControl& command_control) = 0;
282 virtual RequestLtrim Ltrim(std::string key, int64_t start, int64_t stop,
const CommandControl& command_control) = 0;
284 virtual RequestMget Mget(std::vector<std::string> keys,
const CommandControl& command_control) = 0;
287 Mset(std::vector<std::pair<std::string, std::string>> key_values,
const CommandControl& command_control) = 0;
289 virtual TransactionPtr Multi() = 0;
291 virtual TransactionPtr Multi(
Transaction::CheckShards check_shards) = 0;
293 virtual RequestPersist Persist(std::string key,
const CommandControl& command_control) = 0;
295 virtual RequestPexpire
296 Pexpire(std::string key, std::chrono::milliseconds ttl,
const CommandControl& command_control) = 0;
298 virtual RequestPing Ping(size_t shard,
const CommandControl& command_control) = 0;
300 virtual RequestPingMessage Ping(size_t shard, std::string message,
const CommandControl& command_control) = 0;
303 Publish(std::string channel, std::string message,
const CommandControl& command_control, PubShard policy) = 0;
305 virtual void Spublish(std::string channel, std::string message,
const CommandControl& command_control) = 0;
307 virtual RequestRename Rename(std::string key, std::string new_key,
const CommandControl& command_control) = 0;
309 virtual RequestRpop Rpop(std::string key,
const CommandControl& command_control) = 0;
311 virtual RequestRpush Rpush(std::string key, std::string value,
const CommandControl& command_control) = 0;
314 Rpush(std::string key, std::vector<std::string> values,
const CommandControl& command_control) = 0;
316 virtual RequestRpushx Rpushx(std::string key, std::string element,
const CommandControl& command_control) = 0;
322 virtual RequestSadd
Sadd(std::string key, std::string member,
const CommandControl& command_control) = 0;
332 virtual RequestScan
Scan(size_t shard, ScanOptions options,
const CommandControl& command_control) = 0;
334 virtual RequestScard Scard(std::string key,
const CommandControl& command_control) = 0;
336 virtual RequestSet Set(std::string key, std::string value,
const CommandControl& command_control) = 0;
339 Set(std::string key, std::string value, std::chrono::milliseconds ttl,
const CommandControl& command_control) = 0;
341 virtual RequestSetIfExist SetIfExist(std::string key, std::string value,
const CommandControl& command_control) = 0;
343 virtual RequestSetIfExist SetIfExist(
346 std::chrono::milliseconds ttl,
350 virtual RequestSetIfNotExist
351 SetIfNotExist(std::string key, std::string value,
const CommandControl& command_control) = 0;
353 virtual RequestSetIfNotExist SetIfNotExist(
356 std::chrono::milliseconds ttl,
360 virtual RequestSetIfNotExistOrGet
361 SetIfNotExistOrGet(std::string key, std::string value,
const CommandControl& command_control) = 0;
363 virtual RequestSetIfNotExistOrGet SetIfNotExistOrGet(
366 std::chrono::milliseconds ttl,
371 Setex(std::string key, std::chrono::seconds seconds, std::string value,
const CommandControl& command_control) = 0;
373 virtual RequestSismember Sismember(std::string key, std::string member,
const CommandControl& command_control) = 0;
376 virtual RequestSmembers Smembers(std::string key,
const CommandControl& command_control) = 0;
378 virtual RequestSrandmember Srandmember(std::string key,
const CommandControl& command_control) = 0;
380 virtual RequestSrandmembers Srandmembers(std::string key, int64_t count,
const CommandControl& command_control) = 0;
382 virtual RequestSrem Srem(std::string key, std::string member,
const CommandControl& command_control) = 0;
385 Srem(std::string key, std::vector<std::string> members,
const CommandControl& command_control) = 0;
391 virtual RequestSscan
Sscan(std::string key, SscanOptions options,
const CommandControl& command_control) = 0;
393 virtual RequestStrlen Strlen(std::string key,
const CommandControl& command_control) = 0;
395 virtual RequestTime Time(size_t shard,
const CommandControl& command_control) = 0;
397 virtual RequestTtl Ttl(std::string key,
const CommandControl& command_control) = 0;
399 virtual RequestType Type(std::string key,
const CommandControl& command_control) = 0;
402 Zadd(std::string key,
double score, std::string member,
const CommandControl& command_control) = 0;
404 virtual RequestZadd Zadd(
412 virtual RequestZadd Zadd(
414 std::vector<std::pair<
double, std::string>> scored_members,
418 virtual RequestZadd Zadd(
420 std::vector<std::pair<
double, std::string>> scored_members,
425 virtual RequestZaddIncr
426 ZaddIncr(std::string key,
double score, std::string member,
const CommandControl& command_control) = 0;
428 virtual RequestZaddIncrExisting
429 ZaddIncrExisting(std::string key,
double score, std::string member,
const CommandControl& command_control) = 0;
431 virtual RequestZcard Zcard(std::string key,
const CommandControl& command_control) = 0;
433 virtual RequestZcount Zcount(std::string key,
double min,
double max,
const CommandControl& command_control) = 0;
435 virtual RequestZrange
436 Zrange(std::string key, int64_t start, int64_t stop,
const CommandControl& command_control) = 0;
438 virtual RequestZrangeWithScores
439 ZrangeWithScores(std::string key, int64_t start, int64_t stop,
const CommandControl& command_control) = 0;
441 virtual RequestZrangebyscore
442 Zrangebyscore(std::string key,
double min,
double max,
const CommandControl& command_control) = 0;
444 virtual RequestZrangebyscore
445 Zrangebyscore(std::string key, std::string min, std::string max,
const CommandControl& command_control) = 0;
447 virtual RequestZrangebyscore Zrangebyscore(
455 virtual RequestZrangebyscore Zrangebyscore(
463 virtual RequestZrangebyscoreWithScores
464 ZrangebyscoreWithScores(std::string key,
double min,
double max,
const CommandControl& command_control) = 0;
466 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
473 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
481 virtual RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
489 virtual RequestZrem Zrem(std::string key, std::string member,
const CommandControl& command_control) = 0;
492 Zrem(std::string key, std::vector<std::string> members,
const CommandControl& command_control) = 0;
494 virtual RequestZremrangebyrank
495 Zremrangebyrank(std::string key, int64_t start, int64_t stop,
const CommandControl& command_control) = 0;
497 virtual RequestZremrangebyscore
498 Zremrangebyscore(std::string key,
double min,
double max,
const CommandControl& command_control) = 0;
500 virtual RequestZremrangebyscore
501 Zremrangebyscore(std::string key, std::string min, std::string max,
const CommandControl& command_control) = 0;
507 virtual RequestZscan
Zscan(std::string key, ZscanOptions options,
const CommandControl& command_control) = 0;
509 virtual RequestZscore Zscore(std::string key, std::string member,
const CommandControl& command_control) = 0;
520 void Publish(std::string channel, std::string message,
const CommandControl& command_control);
522 RequestScan Scan(size_t shard,
const CommandControl& command_control);
524 RequestHscan Hscan(std::string key,
const CommandControl& command_control);
526 RequestSscan Sscan(std::string key,
const CommandControl& command_control);
528 RequestZscan Zscan(std::string key,
const CommandControl& command_control);
531 virtual RequestEvalCommon EvalCommon(
533 std::vector<std::string> keys,
534 std::vector<std::string> args,
537 virtual RequestEvalShaCommon EvalShaCommon(
538 std::string script_hash,
539 std::vector<std::string> keys,
540 std::vector<std::string> args,
543 virtual RequestGenericCommon GenericCommon(
545 std::vector<std::string> args,