42class MockClientBase :
public Client,
public std::enable_shared_from_this<MockClientBase> {
46 ~MockClientBase()
override;
51 size_t ShardsCount()
const override;
52 bool IsInClusterMode()
const override;
54 size_t ShardByKey(
const std::string& key)
const override;
58 RequestAppend Append(std::string key, std::string value,
const CommandControl& command_control)
override;
63 std::vector<std::string> src_keys,
67 RequestDbsize Dbsize(
size_t shard,
const CommandControl& command_control)
override;
69 RequestDecr Decr(std::string key,
const CommandControl& command_control)
override;
71 RequestDel Del(std::string key,
const CommandControl& command_control)
override;
73 RequestDel Del(std::vector<std::string> keys,
const CommandControl& command_control)
override;
75 RequestUnlink Unlink(std::string key,
const CommandControl& command_control)
override;
77 RequestUnlink Unlink(std::vector<std::string> keys,
const CommandControl& command_control)
override;
79 RequestEvalCommon EvalCommon(
81 std::vector<std::string> keys,
82 std::vector<std::string> args,
85 RequestEvalShaCommon EvalShaCommon(
87 std::vector<std::string> keys,
88 std::vector<std::string> args,
91 RequestEvalCommon EvalReadOnlyCommon(
93 std::vector<std::string> keys,
94 std::vector<std::string> args,
97 RequestEvalShaCommon EvalShaReadOnlyCommon(
99 std::vector<std::string> keys,
100 std::vector<std::string> args,
103 RequestGenericCommon GenericCommon(
105 std::vector<std::string> args,
112 RequestExists Exists(std::string key,
const CommandControl& command_control)
override;
114 RequestExists Exists(std::vector<std::string> keys,
const CommandControl& command_control)
override;
116 RequestExpire Expire(std::string key, std::chrono::seconds ttl,
const CommandControl& command_control)
override;
118 RequestExpire Expire(
120 std::chrono::seconds ttl,
127 RequestGeoadd Geoadd(std::string key, std::vector<GeoaddArg> point_members,
const CommandControl& command_control)
130 RequestGeopos Geopos(std::string key, std::vector<std::string> members,
const CommandControl& command_control)
133 RequestGeoradius Georadius(
142 RequestGeosearch Geosearch(
150 RequestGeosearch Geosearch(
159 RequestGeosearch Geosearch(
168 RequestGeosearch Geosearch(
178 RequestGet Get(std::string key,
const CommandControl& command_control)
override;
182 RequestGetset Getset(std::string key, std::string value,
const CommandControl& command_control)
override;
184 RequestHdel Hdel(std::string key, std::string field,
const CommandControl& command_control)
override;
186 RequestHdel Hdel(std::string key, std::vector<std::string> fields,
const CommandControl& command_control)
override;
188 RequestHexists Hexists(std::string key, std::string field,
const CommandControl& command_control)
override;
190 RequestHget Hget(std::string key, std::string field,
const CommandControl& command_control)
override;
192 RequestHgetall Hgetall(std::string key,
const CommandControl& command_control)
override;
194 RequestHincrby Hincrby(std::string key, std::string field, int64_t increment,
const CommandControl& command_control)
197 RequestHincrbyfloat Hincrbyfloat(
204 RequestHkeys Hkeys(std::string key,
const CommandControl& command_control)
override;
206 RequestHlen Hlen(std::string key,
const CommandControl& command_control)
override;
208 RequestHmget Hmget(std::string key, std::vector<std::string> fields,
const CommandControl& command_control)
213 std::vector<std::pair<std::string, std::string>> field_values,
220 RequestHset Hset(std::string key, std::string field, std::string value,
const CommandControl& command_control)
223 RequestHsetnx Hsetnx(std::string key, std::string field, std::string value,
const CommandControl& command_control)
226 RequestHvals Hvals(std::string key,
const CommandControl& command_control)
override;
228 RequestIncr Incr(std::string key,
const CommandControl& command_control)
override;
230 RequestKeys Keys(std::string keys_pattern,
size_t shard,
const CommandControl& command_control)
override;
232 RequestLindex Lindex(std::string key, int64_t index,
const CommandControl& command_control)
override;
234 RequestLlen Llen(std::string key,
const CommandControl& command_control)
override;
236 RequestLpop Lpop(std::string key,
const CommandControl& command_control)
override;
238 RequestLpush Lpush(std::string key, std::string value,
const CommandControl& command_control)
override;
240 RequestLpush Lpush(std::string key, std::vector<std::string> values,
const CommandControl& command_control)
243 RequestLpushx Lpushx(std::string key, std::string element,
const CommandControl& command_control)
override;
245 RequestLrange Lrange(std::string key, int64_t start, int64_t stop,
const CommandControl& command_control)
override;
247 RequestLrem Lrem(std::string key, int64_t count, std::string element,
const CommandControl& command_control)
250 RequestLtrim Ltrim(std::string key, int64_t start, int64_t stop,
const CommandControl& command_control)
override;
252 RequestMget Mget(std::vector<std::string> keys,
const CommandControl& command_control)
override;
254 RequestMset Mset(std::vector<std::pair<std::string, std::string>> key_values,
const CommandControl& command_control)
258 std::vector<std::pair<std::string, std::string>> key_values,
263 std::vector<std::pair<std::string, std::string>> key_values,
268 RequestPersist Persist(std::string key,
const CommandControl& command_control)
override;
270 RequestPexpire Pexpire(std::string key, std::chrono::milliseconds ttl,
const CommandControl& command_control)
273 RequestPing Ping(
size_t shard,
const CommandControl& command_control)
override;
275 RequestPingMessage Ping(
size_t shard, std::string message,
const CommandControl& command_control)
override;
277 void Publish(std::string channel, std::string message,
const CommandControl& command_control, PubShard policy)
280 void Spublish(std::string channel, std::string message,
const CommandControl& command_control)
override;
282 RequestRename Rename(std::string key, std::string new_key,
const CommandControl& command_control)
override;
284 RequestRpop Rpop(std::string key,
const CommandControl& command_control)
override;
286 RequestRpush Rpush(std::string key, std::string value,
const CommandControl& command_control)
override;
288 RequestRpush Rpush(std::string key, std::vector<std::string> values,
const CommandControl& command_control)
291 RequestRpushx Rpushx(std::string key, std::string element,
const CommandControl& command_control)
override;
293 RequestSadd
Sadd(std::string key, std::string member,
const CommandControl& command_control)
override;
295 RequestSadd
Sadd(std::string key, std::vector<std::string> members,
const CommandControl& command_control)
override;
299 RequestScard Scard(std::string key,
const CommandControl& command_control)
override;
301 RequestSet Set(std::string key, std::string value,
const CommandControl& command_control)
override;
306 std::chrono::milliseconds ttl,
310 RequestSetIfExist SetIfExist(std::string key, std::string value,
const CommandControl& command_control)
override;
312 RequestSetIfExist SetIfExist(
315 std::chrono::milliseconds ttl,
319 RequestSetIfNotExist SetIfNotExist(std::string key, std::string value,
const CommandControl& command_control)
322 RequestSetIfNotExist SetIfNotExist(
325 std::chrono::milliseconds ttl,
329 RequestSetIfNotExistOrGet SetIfNotExistOrGet(
335 RequestSetIfNotExistOrGet SetIfNotExistOrGet(
338 std::chrono::milliseconds ttl,
344 std::chrono::seconds seconds,
349 RequestSetAndGetPrevious SetAndGetPrevious(
352 std::chrono::milliseconds ttl,
356 RequestSismember Sismember(std::string key, std::string member,
const CommandControl& command_control)
override;
358 RequestSmembers Smembers(std::string key,
const CommandControl& command_control)
override;
360 RequestSrandmember Srandmember(std::string key,
const CommandControl& command_control)
override;
362 RequestSrandmembers Srandmembers(std::string key, int64_t count,
const CommandControl& command_control)
override;
364 RequestSrem Srem(std::string key, std::string member,
const CommandControl& command_control)
override;
366 RequestSrem Srem(std::string key, std::vector<std::string> members,
const CommandControl& command_control)
override;
371 RequestStrlen Strlen(std::string key,
const CommandControl& command_control)
override;
373 RequestTime Time(
size_t shard,
const CommandControl& command_control)
override;
375 RequestTtl Ttl(std::string key,
const CommandControl& command_control)
override;
377 RequestType Type(std::string key,
const CommandControl& command_control)
override;
379 RequestZadd Zadd(std::string key,
double score, std::string member,
const CommandControl& command_control)
override;
391 std::vector<std::pair<double, std::string>> scored_members,
397 std::vector<std::pair<double, std::string>> scored_members,
402 RequestZaddIncr ZaddIncr(std::string key,
double score, std::string member,
const CommandControl& command_control)
405 RequestZaddIncrExisting ZaddIncrExisting(
412 RequestZcard Zcard(std::string key,
const CommandControl& command_control)
override;
414 RequestZcount Zcount(std::string key,
double min,
double max,
const CommandControl& command_control)
override;
416 RequestZrange Zrange(std::string key, int64_t start, int64_t stop,
const CommandControl& command_control)
override;
418 RequestZrangeWithScores ZrangeWithScores(
425 RequestZrangebyscore Zrangebyscore(std::string key,
double min,
double max,
const CommandControl& command_control)
428 RequestZrangebyscore Zrangebyscore(
435 RequestZrangebyscore Zrangebyscore(
443 RequestZrangebyscore Zrangebyscore(
451 RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
458 RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
465 RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
473 RequestZrangebyscoreWithScores ZrangebyscoreWithScores(
481 RequestZrem Zrem(std::string key, std::string member,
const CommandControl& command_control)
override;
483 RequestZrem Zrem(std::string key, std::vector<std::string> members,
const CommandControl& command_control)
override;
485 RequestZremrangebyrank Zremrangebyrank(
492 RequestZremrangebyscore Zremrangebyscore(
499 RequestZremrangebyscore Zremrangebyscore(
509 RequestZscore Zscore(std::string key, std::string member,
const CommandControl& command_control)
override;
513 std::chrono::seconds ttl,
514 std::vector<std::string> fields,
520 std::chrono::seconds ttl,
522 std::vector<std::string> fields,
528 std::chrono::milliseconds ttl,
529 std::vector<std::string> fields,
535 std::chrono::milliseconds ttl,
537 std::vector<std::string> fields,
543 std::chrono::system_clock::time_point deadline,
544 std::vector<std::string> fields,
550 std::chrono::system_clock::time_point deadline,
552 std::vector<std::string> fields,
558 std::chrono::system_clock::time_point deadline,
559 std::vector<std::string> fields,
565 std::chrono::system_clock::time_point deadline,
567 std::vector<std::string> fields,
573 std::vector<std::string> fields,
579 std::vector<std::string> fields,
583 RequestHttl
Httl(std::string key, std::vector<std::string> fields,
const CommandControl& command_control)
override;
585 RequestHpttl
Hpttl(std::string key, std::vector<std::string> fields,
const CommandControl& command_control)
597 std::vector<std::string> fields,
603 std::vector<HsetexFieldValue> field_values,
610 std::vector<HsetexFieldValue> field_values,
650 TransactionPtr Multi() final;
652 TransactionPtr Multi(
Transaction::CheckShards check_shards) final;
658 virtual std::unique_ptr<MockTransactionImplBase> operator()()
const = 0;
661 template <
typename MockTransactionImpl>
662 void SetMockTransactionImplType() {
663 mock_transaction_impl_creator_ = std::make_shared<MockTransactionImplCreator<MockTransactionImpl>>();
666 void SetMockTransactionImplCreator(std::shared_ptr<MockTransactionImplCreatorBase> mock_transaction_impl_creator) {
667 mock_transaction_impl_creator_ = std::move(mock_transaction_impl_creator);
671 std::shared_ptr<MockTransactionImplCreatorBase> mock_transaction_impl_creator,
672 std::optional<size_t> force_shard_idx
676 template <
typename MockTransactionImpl>
677 class MockTransactionImplCreator :
public MockTransactionImplCreatorBase {
679 std::unique_ptr<MockTransactionImplBase> operator()()
const override {
680 return std::make_unique<MockTransactionImpl>();
684 std::shared_ptr<MockTransactionImplCreatorBase> mock_transaction_impl_creator_;
685 std::optional<size_t> force_shard_idx_;