userver: storages::redis::MockClientBase Class Reference
Loading...
Searching...
No Matches
storages::redis::MockClientBase Class Reference

#include <userver/storages/redis/mock_client_base.hpp>

Detailed Description

Base class for mocked redis clients in unit tests.

Please create clients with std::make_shared. Otherwise Multi() command will not work in mocked client. You should override methods for redis commands used in test. In overridden methods you can use CreateMockRequest* helpers. Examples (for Hget command): return storages::redis::CreateMockRequest< storages::redis::RequestHget>(std::string{"value"}); return storages::redis::CreateMockRequest< storages::redis::RequestHget>(std::nullopt); Mocking timeout error from redis server: return storages::redis::CreateMockRequestTimeout< storages::redis::RequestHget>(); For *scan commands use CreateMockRequestScan helper: return storages::redis::CreateMockRequestScan< storages::redis::ScanTag::kScan>({"keya", "keyb", "keyc"});

Definition at line 42 of file mock_client_base.hpp.

Inheritance diagram for storages::redis::MockClientBase:

Classes

class  MockTransactionImplCreatorBase

Public Member Functions

void WaitConnectedOnce (RedisWaitConnected wait_connected) override
bool IsReady (const HealthCheckParams &params) const override
size_t ShardsCount () const override
bool IsInClusterMode () const override
size_t ShardByKey (const std::string &key) const override
RequestAppend Append (std::string key, std::string value, const CommandControl &command_control) override
RequestBitop Bitop (BitOperation op, std::string dest_key, std::vector< std::string > src_keys, const CommandControl &command_control) override
RequestDbsize Dbsize (size_t shard, const CommandControl &command_control) override
RequestDecr Decr (std::string key, const CommandControl &command_control) override
RequestDel Del (std::string key, const CommandControl &command_control) override
RequestDel Del (std::vector< std::string > keys, const CommandControl &command_control) override
RequestUnlink Unlink (std::string key, const CommandControl &command_control) override
RequestUnlink Unlink (std::vector< std::string > keys, const CommandControl &command_control) override
RequestEvalCommon EvalCommon (std::string script, std::vector< std::string > keys, std::vector< std::string > args, const CommandControl &command_control) override
RequestEvalShaCommon EvalShaCommon (std::string script, std::vector< std::string > keys, std::vector< std::string > args, const CommandControl &command_control) override
RequestEvalCommon EvalReadOnlyCommon (std::string script, std::vector< std::string > keys, std::vector< std::string > args, const CommandControl &command_control) override
RequestEvalShaCommon EvalShaReadOnlyCommon (std::string script, std::vector< std::string > keys, std::vector< std::string > args, const CommandControl &command_control) override
RequestGenericCommon GenericCommon (std::string command, std::vector< std::string > args, size_t key_index, const CommandControl &command_control) override
RequestScriptLoad ScriptLoad (std::string script, size_t shard, const CommandControl &command_control) override
 Load the script to the server for further execution via EvalSha() member function.
RequestExists Exists (std::string key, const CommandControl &command_control) override
RequestExists Exists (std::vector< std::string > keys, const CommandControl &command_control) override
RequestExpire Expire (std::string key, std::chrono::seconds ttl, const CommandControl &command_control) override
RequestExpire Expire (std::string key, std::chrono::seconds ttl, ExpireOptions options, const CommandControl &command_control) override
RequestGeoadd Geoadd (std::string key, GeoaddArg point_member, const CommandControl &command_control) override
RequestGeoadd Geoadd (std::string key, std::vector< GeoaddArg > point_members, const CommandControl &command_control) override
RequestGeopos Geopos (std::string key, std::vector< std::string > members, const CommandControl &command_control) override
RequestGeoradius Georadius (std::string key, Longitude lon, Latitude lat, double radius, const GeoradiusOptions &georadius_options, const CommandControl &command_control) override
RequestGeosearch Geosearch (std::string key, std::string member, double radius, const GeosearchOptions &geosearch_options, const CommandControl &command_control) override
RequestGeosearch Geosearch (std::string key, std::string member, BoxWidth width, BoxHeight height, const GeosearchOptions &geosearch_options, const CommandControl &command_control) override
RequestGeosearch Geosearch (std::string key, Longitude lon, Latitude lat, double radius, const GeosearchOptions &geosearch_options, const CommandControl &command_control) override
RequestGeosearch Geosearch (std::string key, Longitude lon, Latitude lat, BoxWidth width, BoxHeight height, const GeosearchOptions &geosearch_options, const CommandControl &command_control) override
RequestGet Get (std::string key, const CommandControl &command_control) override
RequestGetdel Getdel (std::string key, const CommandControl &command_control) override
 Atomically returns the string value of a key and deletes the key.
RequestGetset Getset (std::string key, std::string value, const CommandControl &command_control) override
RequestHdel Hdel (std::string key, std::string field, const CommandControl &command_control) override
RequestHdel Hdel (std::string key, std::vector< std::string > fields, const CommandControl &command_control) override
RequestHexists Hexists (std::string key, std::string field, const CommandControl &command_control) override
RequestHget Hget (std::string key, std::string field, const CommandControl &command_control) override
RequestHgetall Hgetall (std::string key, const CommandControl &command_control) override
RequestHincrby Hincrby (std::string key, std::string field, int64_t increment, const CommandControl &command_control) override
RequestHincrbyfloat Hincrbyfloat (std::string key, std::string field, double increment, const CommandControl &command_control) override
RequestHkeys Hkeys (std::string key, const CommandControl &command_control) override
RequestHlen Hlen (std::string key, const CommandControl &command_control) override
RequestHmget Hmget (std::string key, std::vector< std::string > fields, const CommandControl &command_control) override
RequestHmset Hmset (std::string key, std::vector< std::pair< std::string, std::string > > field_values, const CommandControl &command_control) override
ScanRequest< ScanTag::kHscan > Hscan (std::string key, HscanOptions options, const CommandControl &command_control) override
 Iterate over a collection of elements.
RequestHset Hset (std::string key, std::string field, std::string value, const CommandControl &command_control) override
RequestHsetnx Hsetnx (std::string key, std::string field, std::string value, const CommandControl &command_control) override
RequestHvals Hvals (std::string key, const CommandControl &command_control) override
RequestIncr Incr (std::string key, const CommandControl &command_control) override
RequestKeys Keys (std::string keys_pattern, size_t shard, const CommandControl &command_control) override
RequestLindex Lindex (std::string key, int64_t index, const CommandControl &command_control) override
RequestLlen Llen (std::string key, const CommandControl &command_control) override
RequestLpop Lpop (std::string key, const CommandControl &command_control) override
RequestLpush Lpush (std::string key, std::string value, const CommandControl &command_control) override
RequestLpush Lpush (std::string key, std::vector< std::string > values, const CommandControl &command_control) override
RequestLpushx Lpushx (std::string key, std::string element, const CommandControl &command_control) override
RequestLrange Lrange (std::string key, int64_t start, int64_t stop, const CommandControl &command_control) override
RequestLrem Lrem (std::string key, int64_t count, std::string element, const CommandControl &command_control) override
RequestLtrim Ltrim (std::string key, int64_t start, int64_t stop, const CommandControl &command_control) override
RequestMget Mget (std::vector< std::string > keys, const CommandControl &command_control) override
RequestMset Mset (std::vector< std::pair< std::string, std::string > > key_values, const CommandControl &command_control) override
RequestMsetex Msetex (std::vector< std::pair< std::string, std::string > > key_values, const CommandControl &command_control) override
 Atomically set multiple key-value pairs, without an expiration clause.
RequestMsetex Msetex (std::vector< std::pair< std::string, std::string > > key_values, MsetexOptions options, const CommandControl &command_control) override
 Atomically set multiple key-value pairs with optional existence and TTL conditions.
RequestPersist Persist (std::string key, const CommandControl &command_control) override
RequestPexpire Pexpire (std::string key, std::chrono::milliseconds ttl, const CommandControl &command_control) override
RequestPing Ping (size_t shard, const CommandControl &command_control) override
RequestPingMessage Ping (size_t shard, std::string message, const CommandControl &command_control) override
void Publish (std::string channel, std::string message, const CommandControl &command_control, PubShard policy) override
void Spublish (std::string channel, std::string message, const CommandControl &command_control) override
RequestRename Rename (std::string key, std::string new_key, const CommandControl &command_control) override
RequestRpop Rpop (std::string key, const CommandControl &command_control) override
RequestRpush Rpush (std::string key, std::string value, const CommandControl &command_control) override
RequestRpush Rpush (std::string key, std::vector< std::string > values, const CommandControl &command_control) override
RequestRpushx Rpushx (std::string key, std::string element, const CommandControl &command_control) override
RequestSadd Sadd (std::string key, std::string member, const CommandControl &command_control) override
 Add member to a set of elements.
RequestSadd Sadd (std::string key, std::vector< std::string > members, const CommandControl &command_control) override
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
ScanRequest< ScanTag::kScan > Scan (size_t shard, ScanOptions options, const CommandControl &command_control) override
 Iterate over a collection of elements.
RequestScard Scard (std::string key, const CommandControl &command_control) override
RequestSet Set (std::string key, std::string value, const CommandControl &command_control) override
RequestSet Set (std::string key, std::string value, std::chrono::milliseconds ttl, const CommandControl &command_control) override
RequestSetIfExist SetIfExist (std::string key, std::string value, const CommandControl &command_control) override
RequestSetIfExist SetIfExist (std::string key, std::string value, std::chrono::milliseconds ttl, const CommandControl &command_control) override
RequestSetIfNotExist SetIfNotExist (std::string key, std::string value, const CommandControl &command_control) override
RequestSetIfNotExist SetIfNotExist (std::string key, std::string value, std::chrono::milliseconds ttl, const CommandControl &command_control) override
RequestSetIfNotExistOrGet SetIfNotExistOrGet (std::string key, std::string value, const CommandControl &command_control) override
RequestSetIfNotExistOrGet SetIfNotExistOrGet (std::string key, std::string value, std::chrono::milliseconds ttl, const CommandControl &command_control) override
RequestSetex Setex (std::string key, std::chrono::seconds seconds, std::string value, const CommandControl &command_control) override
RequestSetAndGetPrevious SetAndGetPrevious (std::string key, std::string value, std::chrono::milliseconds ttl, const CommandControl &command_control) override
RequestSismember Sismember (std::string key, std::string member, const CommandControl &command_control) override
RequestSmembers Smembers (std::string key, const CommandControl &command_control) override
RequestSrandmember Srandmember (std::string key, const CommandControl &command_control) override
RequestSrandmembers Srandmembers (std::string key, int64_t count, const CommandControl &command_control) override
RequestSrem Srem (std::string key, std::string member, const CommandControl &command_control) override
RequestSrem Srem (std::string key, std::vector< std::string > members, const CommandControl &command_control) override
ScanRequest< ScanTag::kSscan > Sscan (std::string key, SscanOptions options, const CommandControl &command_control) override
 Iterate over a collection of elements.
RequestStrlen Strlen (std::string key, const CommandControl &command_control) override
RequestTime Time (size_t shard, const CommandControl &command_control) override
RequestTtl Ttl (std::string key, const CommandControl &command_control) override
RequestType Type (std::string key, const CommandControl &command_control) override
RequestZadd Zadd (std::string key, double score, std::string member, const CommandControl &command_control) override
RequestZadd Zadd (std::string key, double score, std::string member, const ZaddOptions &options, const CommandControl &command_control) override
RequestZadd Zadd (std::string key, std::vector< std::pair< double, std::string > > scored_members, const CommandControl &command_control) override
RequestZadd Zadd (std::string key, std::vector< std::pair< double, std::string > > scored_members, const ZaddOptions &options, const CommandControl &command_control) override
RequestZaddIncr ZaddIncr (std::string key, double score, std::string member, const CommandControl &command_control) override
RequestZaddIncrExisting ZaddIncrExisting (std::string key, double score, std::string member, const CommandControl &command_control) override
RequestZcard Zcard (std::string key, const CommandControl &command_control) override
RequestZcount Zcount (std::string key, double min, double max, const CommandControl &command_control) override
RequestZrange Zrange (std::string key, int64_t start, int64_t stop, const CommandControl &command_control) override
RequestZrangeWithScores ZrangeWithScores (std::string key, int64_t start, int64_t stop, const CommandControl &command_control) override
RequestZrangebyscore Zrangebyscore (std::string key, double min, double max, const CommandControl &command_control) override
RequestZrangebyscore Zrangebyscore (std::string key, std::string min, std::string max, const CommandControl &command_control) override
RequestZrangebyscore Zrangebyscore (std::string key, double min, double max, const RangeOptions &range_options, const CommandControl &command_control) override
RequestZrangebyscore Zrangebyscore (std::string key, std::string min, std::string max, const RangeOptions &range_options, const CommandControl &command_control) override
RequestZrangebyscoreWithScores ZrangebyscoreWithScores (std::string key, double min, double max, const CommandControl &command_control) override
RequestZrangebyscoreWithScores ZrangebyscoreWithScores (std::string key, std::string min, std::string max, const CommandControl &command_control) override
RequestZrangebyscoreWithScores ZrangebyscoreWithScores (std::string key, double min, double max, const RangeOptions &range_options, const CommandControl &command_control) override
RequestZrangebyscoreWithScores ZrangebyscoreWithScores (std::string key, std::string min, std::string max, const RangeOptions &range_options, const CommandControl &command_control) override
RequestZrem Zrem (std::string key, std::string member, const CommandControl &command_control) override
RequestZrem Zrem (std::string key, std::vector< std::string > members, const CommandControl &command_control) override
RequestZremrangebyrank Zremrangebyrank (std::string key, int64_t start, int64_t stop, const CommandControl &command_control) override
RequestZremrangebyscore Zremrangebyscore (std::string key, double min, double max, const CommandControl &command_control) override
RequestZremrangebyscore Zremrangebyscore (std::string key, std::string min, std::string max, const CommandControl &command_control) override
ScanRequest< ScanTag::kZscan > Zscan (std::string key, ZscanOptions options, const CommandControl &command_control) override
 Iterate over a collection of elements.
RequestZscore Zscore (std::string key, std::string member, const CommandControl &command_control) override
RequestHexpire Hexpire (std::string key, std::chrono::seconds ttl, std::vector< std::string > fields, const CommandControl &command_control) override
 Set TTL (in seconds) on one or more hash fields (HEXPIRE).
RequestHexpire Hexpire (std::string key, std::chrono::seconds ttl, ExpireOptions options, std::vector< std::string > fields, const CommandControl &command_control) override
 Set TTL (in seconds) on one or more hash fields with NX/XX/GT/LT modifier (HEXPIRE).
RequestHexpire Hpexpire (std::string key, std::chrono::milliseconds ttl, std::vector< std::string > fields, const CommandControl &command_control) override
 Set TTL (in milliseconds) on one or more hash fields (HPEXPIRE).
RequestHexpire Hpexpire (std::string key, std::chrono::milliseconds ttl, ExpireOptions options, std::vector< std::string > fields, const CommandControl &command_control) override
 Set TTL (in milliseconds) on one or more hash fields with NX/XX/GT/LT modifier (HPEXPIRE).
RequestHexpire Hexpireat (std::string key, std::chrono::system_clock::time_point deadline, std::vector< std::string > fields, const CommandControl &command_control) override
 Set absolute expiration deadline on one or more hash fields (HEXPIREAT, seconds-precision).
RequestHexpire Hexpireat (std::string key, std::chrono::system_clock::time_point deadline, ExpireOptions options, std::vector< std::string > fields, const CommandControl &command_control) override
 Set absolute expiration deadline on one or more hash fields with modifier (HEXPIREAT).
RequestHexpire Hpexpireat (std::string key, std::chrono::system_clock::time_point deadline, std::vector< std::string > fields, const CommandControl &command_control) override
 Set absolute expiration deadline on one or more hash fields (HPEXPIREAT, ms-precision).
RequestHexpire Hpexpireat (std::string key, std::chrono::system_clock::time_point deadline, ExpireOptions options, std::vector< std::string > fields, const CommandControl &command_control) override
 Set absolute expiration deadline on one or more hash fields with modifier (HPEXPIREAT).
RequestHexpiretime Hexpiretime (std::string key, std::vector< std::string > fields, const CommandControl &command_control) override
 Get absolute expiration unix timestamp (seconds) of one or more hash fields (HEXPIRETIME).
RequestHpexpiretime Hpexpiretime (std::string key, std::vector< std::string > fields, const CommandControl &command_control) override
 Get absolute expiration unix timestamp (ms) of one or more hash fields (HPEXPIRETIME).
RequestHttl Httl (std::string key, std::vector< std::string > fields, const CommandControl &command_control) override
 Get remaining TTL (in seconds) of one or more hash fields (HTTL).
RequestHpttl Hpttl (std::string key, std::vector< std::string > fields, const CommandControl &command_control) override
 Get remaining TTL (in milliseconds) of one or more hash fields (HPTTL).
RequestHpersist Hpersist (std::string key, std::vector< std::string > fields, const CommandControl &command_control) override
 Remove the TTL from one or more hash fields.
RequestHgetex Hgetex (std::string key, std::vector< std::string > fields, const CommandControl &command_control) override
 Get the values of one or more hash fields.
RequestHgetex Hgetex (std::string key, HgetexOptions options, std::vector< std::string > fields, const CommandControl &command_control) override
 Get the values of one or more hash fields, optionally updating their TTL.
RequestHsetex Hsetex (std::string key, std::vector< HsetexFieldValue > field_values, const CommandControl &command_control) override
 Set one or more field/value pairs in a hash without a TTL clause.
RequestHsetex Hsetex (std::string key, HsetexOptions options, std::vector< HsetexFieldValue > field_values, const CommandControl &command_control) override
 Set one or more field/value pairs in a hash with optional FNX|FXX and TTL modifiers.
RequestJsonSet JsonSet (std::string key, std::string path, formats::json::Value value, const CommandControl &command_control) override
 Set a JSON value at the given key and path.
RequestJsonSetIfNotExist JsonSetIfNotExist (std::string key, std::string path, formats::json::Value value, const CommandControl &command_control) override
 Set a JSON value only if the path does not already exist (NX).
RequestJsonSetIfExist JsonSetIfExist (std::string key, std::string path, formats::json::Value value, const CommandControl &command_control) override
 Set a JSON value only if the path already exists (XX).
RequestJsonGet JsonGet (std::string key, const CommandControl &command_control) override
 Get the JSON value at the root path of the given key.
RequestJsonGet JsonGet (std::string key, std::string path, const CommandControl &command_control) override
 Get the JSON value at the given path of the given key.
RequestJsonGet JsonGet (std::string key, std::vector< std::string > paths, const CommandControl &command_control) override
 Get the JSON value at multiple paths of the given key.
RequestJsonMget JsonMget (std::vector< std::string > keys, std::string path, const CommandControl &command_control) override
 Get JSON values from multiple keys at the given path.
RequestJsonMset JsonMset (std::vector< JsonKeyPathValue > key_path_values, const CommandControl &command_control) override
 Set JSON values for multiple key-path-value triplets.
TransactionPtr Multi () final
TransactionPtr Multi (Transaction::CheckShards check_shards) final
template<typename MockTransactionImpl>
void SetMockTransactionImplType ()
void SetMockTransactionImplCreator (std::shared_ptr< MockTransactionImplCreatorBase > mock_transaction_impl_creator)
 MockClientBase (std::shared_ptr< MockTransactionImplCreatorBase > mock_transaction_impl_creator, std::optional< size_t > force_shard_idx)
void CheckShardIdx (size_t shard_idx) const
bool IsReady (WaitConnectedMode mode) const
template<typename ScriptResult, typename ReplyType = ScriptResult>
RequestEval< ScriptResult, ReplyType > Eval (std::string script, std::vector< std::string > keys, std::vector< std::string > args, const CommandControl &command_control)
 Invoke the execution of a server-side Lua script.
template<typename ScriptInfo, typename ReplyType = std::decay_t<ScriptInfo>>
RequestEval< std::decay_t< ScriptInfo >, ReplyType > Eval (const ScriptInfo &script_info, std::vector< std::string > keys, std::vector< std::string > args, const CommandControl &command_control)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename ScriptResult, typename ReplyType = ScriptResult>
RequestEvalSha< ScriptResult, ReplyType > EvalSha (std::string script_hash, std::vector< std::string > keys, std::vector< std::string > args, const CommandControl &command_control)
 Invoke the execution of a server-side Lua script that was previously uploaded to the server via ScriptLoad() member function.
template<typename ScriptResult, typename ReplyType = ScriptResult>
RequestEval< ScriptResult, ReplyType > EvalReadOnly (std::string script, std::vector< std::string > keys, std::vector< std::string > args, const CommandControl &command_control)
 This is a read-only variant of the Eval() command that cannot execute commands that modify data.
template<typename ScriptResult, typename ReplyType = ScriptResult>
RequestEvalSha< ScriptResult, ReplyType > EvalShaReadOnly (std::string script_hash, std::vector< std::string > keys, std::vector< std::string > args, const CommandControl &command_control)
 This is a read-only variant of the EvalSha() command that cannot execute commands that modify data.
template<typename ReplyType>
RequestGeneric< ReplyType > GenericCommand (std::string command, std::vector< std::string > args, size_t key_index, const CommandControl &command_control)
 Execute a custom Redis command.
RequestGet Get (std::string key, RetryNilFromMaster, const CommandControl &command_control)
RequestHget Hget (std::string key, std::string field, RetryNilFromMaster, const CommandControl &command_control)
RequestHscan Hscan (std::string key, const CommandControl &command_control)
void Publish (std::string channel, std::string message, const CommandControl &command_control)
RequestScan Scan (size_t shard, const CommandControl &command_control)
RequestSscan Sscan (std::string key, const CommandControl &command_control)
RequestZscan Zscan (std::string key, const CommandControl &command_control)
RequestZscore Zscore (std::string key, std::string member, RetryNilFromMaster, const CommandControl &command_control)

Member Function Documentation

◆ Append()

RequestAppend storages::redis::MockClientBase::Append ( std::string key,
std::string value,
const CommandControl & command_control )
overridevirtual

◆ Bitop()

RequestBitop storages::redis::MockClientBase::Bitop ( BitOperation op,
std::string dest_key,
std::vector< std::string > src_keys,
const CommandControl & command_control )
overridevirtual

◆ Dbsize()

RequestDbsize storages::redis::MockClientBase::Dbsize ( size_t shard,
const CommandControl & command_control )
overridevirtual

◆ Decr()

RequestDecr storages::redis::MockClientBase::Decr ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Del() [1/2]

RequestDel storages::redis::MockClientBase::Del ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Del() [2/2]

RequestDel storages::redis::MockClientBase::Del ( std::vector< std::string > keys,
const CommandControl & command_control )
overridevirtual

◆ Eval() [1/2]

template<typename ScriptInfo, typename ReplyType = std::decay_t<ScriptInfo>>
RequestEval< std::decay_t< ScriptInfo >, ReplyType > storages::redis::Client::Eval ( const ScriptInfo & script_info,
std::vector< std::string > keys,
std::vector< std::string > args,
const CommandControl & command_control )
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 179 of file client.hpp.

◆ Eval() [2/2]

template<typename ScriptResult, typename ReplyType = ScriptResult>
RequestEval< ScriptResult, ReplyType > storages::redis::Client::Eval ( std::string script,
std::vector< std::string > keys,
std::vector< std::string > args,
const CommandControl & command_control )
inlineinherited

Invoke the execution of a server-side Lua script.

For huge scripts consider EvalSha() to save network bandwidth.

Sample usage:

client->Set("the_key", "the_value", {}).Get();
// ...
const std::string lua_script{R"~(
if redis.call("get",KEYS[1]) == ARGV[1] then
redis.call("del",KEYS[1])
return "del"
else
redis.call("rpush", "mismatched", KEYS[1])
return "mismatched"
end
)~"};
auto val1 = client->Eval<std::string>(lua_script, {"the_key"}, {"mismatched_value"}, kMasterCC).Get();
EXPECT_EQ(val1, "mismatched");
auto val2 = client->Eval<std::string>(lua_script, {"the_key"}, {"the_value"}, kMasterCC).Get();
EXPECT_EQ(val2, "del");

Definition at line 86 of file client.hpp.

◆ EvalCommon()

RequestEvalCommon storages::redis::MockClientBase::EvalCommon ( std::string script,
std::vector< std::string > keys,
std::vector< std::string > args,
const CommandControl & command_control )
overridevirtual

◆ EvalReadOnly()

template<typename ScriptResult, typename ReplyType = ScriptResult>
RequestEval< ScriptResult, ReplyType > storages::redis::Client::EvalReadOnly ( std::string script,
std::vector< std::string > keys,
std::vector< std::string > args,
const CommandControl & command_control )
inlineinherited

This is a read-only variant of the Eval() command that cannot execute commands that modify data.

For huge scripts consider EvalShaReadOnly() to save network bandwidth.

Sample usage:

client->Set("the_key", "the_value", {}).Get();
// Read-only script that reads a key
const std::string read_only_script{R"~(
local value = redis.call("get", KEYS[1])
if value then
return value .. "_from_redis"
else
return nil
end
)~"};
auto val1 = client->EvalReadOnly<std::string>(read_only_script, {"the_key"}, {}, kMasterCC).Get();
EXPECT_EQ(val1, "the_value_from_redis");
// Script that attempts to modify data
const std::string modifying_script{R"~(
redis.call("set", KEYS[1], "modified_value")
return "modified"
)~"};
// EvalReadOnly should fail when script tries to modify data
auto req = client->EvalReadOnly<std::string>(modifying_script, {"the_key"}, {}, kMasterCC);
// Verify the value was not modified
auto final_value = client->Get("the_key", kMasterCC).Get();
ASSERT_TRUE(final_value);
EXPECT_EQ(*final_value, "the_value");

Definition at line 123 of file client.hpp.

◆ EvalReadOnlyCommon()

RequestEvalCommon storages::redis::MockClientBase::EvalReadOnlyCommon ( std::string script,
std::vector< std::string > keys,
std::vector< std::string > args,
const CommandControl & command_control )
overridevirtual

◆ EvalSha()

template<typename ScriptResult, typename ReplyType = ScriptResult>
RequestEvalSha< ScriptResult, ReplyType > storages::redis::Client::EvalSha ( std::string script_hash,
std::vector< std::string > keys,
std::vector< std::string > args,
const CommandControl & command_control )
inlineinherited

Invoke the execution of a server-side Lua script that was previously uploaded to the server via ScriptLoad() member function.

For small scripts consider using a simpler Eval() member function.

Sample usage:

auto upload_scripts = [client]() {
const std::string lua_script{R"~(
if redis.call("get",KEYS[1]) == ARGV[1] then
redis.call("del",KEYS[1])
return "del"
else
redis.call("rpush", "mismatched", KEYS[1])
return "mismatched"
end
)~"};
const std::size_t shards_count = client->ShardsCount();
std::string script_sha;
for (std::size_t i = 0; i < shards_count; ++i) {
script_sha = client->ScriptLoad(lua_script, i, {}).Get();
}
return script_sha;
};
const auto script_sha = upload_scripts();
client->Set("the_key", "the_value", {}).Get();
// ...
auto val1 = client->EvalSha<std::string>(script_sha, {"the_key"}, {"mismatched_value"}, kMasterCC).Get();
if (val1.IsNoScriptError()) {
upload_scripts();
// retry...
val1 = client->EvalSha<std::string>(script_sha, {"the_key"}, {"mismatched_value"}, kMasterCC).Get();
}
EXPECT_EQ(val1.Get(), "mismatched");
auto val2 = client->EvalSha<std::string>(script_sha, {"the_key"}, {"the_value"}, kMasterCC).Get();
if (val2.IsNoScriptError()) {
upload_scripts();
// retry...
val2 = client->EvalSha<std::string>(script_sha, {"the_key"}, {"the_value"}, kMasterCC).Get();
}
EXPECT_EQ(val2.Get(), "del");

Definition at line 105 of file client.hpp.

◆ EvalShaCommon()

RequestEvalShaCommon storages::redis::MockClientBase::EvalShaCommon ( std::string script,
std::vector< std::string > keys,
std::vector< std::string > args,
const CommandControl & command_control )
overridevirtual

◆ EvalShaReadOnly()

template<typename ScriptResult, typename ReplyType = ScriptResult>
RequestEvalSha< ScriptResult, ReplyType > storages::redis::Client::EvalShaReadOnly ( std::string script_hash,
std::vector< std::string > keys,
std::vector< std::string > args,
const CommandControl & command_control )
inlineinherited

This is a read-only variant of the EvalSha() command that cannot execute commands that modify data.

For small scripts consider using a simpler EvalReadOnly() member function.

Sample usage:

auto upload_script = [client](const std::string& lua_script) {
const std::size_t shards_count = client->ShardsCount();
std::string script_sha;
for (std::size_t i = 0; i < shards_count; ++i) {
script_sha = client->ScriptLoad(lua_script, i, {}).Get();
}
return script_sha;
};
// Read-only script that reads a key
const std::string read_only_script{R"~(
local value = redis.call("get", KEYS[1])
if value then
return value .. "_from_redis"
else
return nil
end
)~"};
const auto read_only_script_sha = upload_script(read_only_script);
client->Set("the_key", "the_value", {}).Get();
// Test read-only script execution
auto val1 = client->EvalShaReadOnly<std::string>(read_only_script_sha, {"the_key"}, {}, kMasterCC).Get();
if (val1.IsNoScriptError()) {
upload_script(read_only_script);
// retry...
val1 = client->EvalShaReadOnly<std::string>(read_only_script_sha, {"the_key"}, {}, kMasterCC).Get();
}
EXPECT_EQ(val1.Get(), "the_value_from_redis");
// Script that attempts to modify data
const std::string modifying_script{R"~(
redis.call("set", KEYS[1], "modified_value")
return "modified"
)~"};
const auto modifying_script_sha = upload_script(modifying_script);
// EvalShaReadOnly should fail when script tries to modify data
auto req = client->EvalShaReadOnly<std::string>(modifying_script_sha, {"the_key"}, {}, kMasterCC);
// Verify the value was not modified
auto final_value = client->Get("the_key", kMasterCC).Get();
ASSERT_TRUE(final_value);
EXPECT_EQ(*final_value, "the_value");

Definition at line 141 of file client.hpp.

◆ EvalShaReadOnlyCommon()

RequestEvalShaCommon storages::redis::MockClientBase::EvalShaReadOnlyCommon ( std::string script,
std::vector< std::string > keys,
std::vector< std::string > args,
const CommandControl & command_control )
overridevirtual

◆ Exists() [1/2]

RequestExists storages::redis::MockClientBase::Exists ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Exists() [2/2]

RequestExists storages::redis::MockClientBase::Exists ( std::vector< std::string > keys,
const CommandControl & command_control )
overridevirtual

◆ Expire() [1/2]

RequestExpire storages::redis::MockClientBase::Expire ( std::string key,
std::chrono::seconds ttl,
const CommandControl & command_control )
overridevirtual

◆ Expire() [2/2]

RequestExpire storages::redis::MockClientBase::Expire ( std::string key,
std::chrono::seconds ttl,
ExpireOptions options,
const CommandControl & command_control )
overridevirtual

◆ GenericCommand()

template<typename ReplyType>
RequestGeneric< ReplyType > storages::redis::Client::GenericCommand ( std::string command,
std::vector< std::string > args,
size_t key_index,
const CommandControl & command_control )
inlineinherited

Execute a custom Redis command.

Parameters
commandRedis command name
argscommand arguments
key_indexIndex of the key in the args vector used to determine the shard
command_controlper-command execution options

Sample usage:

client->GenericCommand<void>("set", {"key0", "foo"}, kKeyIndex, command_control).Wait();
EXPECT_EQ(client->GenericCommand<std::string>("get", {"key0"}, kKeyIndex, command_control).Get(), "foo");

Definition at line 161 of file client.hpp.

◆ GenericCommon()

RequestGenericCommon storages::redis::MockClientBase::GenericCommon ( std::string command,
std::vector< std::string > args,
size_t key_index,
const CommandControl & command_control )
overridevirtual

◆ Geoadd() [1/2]

RequestGeoadd storages::redis::MockClientBase::Geoadd ( std::string key,
GeoaddArg point_member,
const CommandControl & command_control )
overridevirtual

◆ Geoadd() [2/2]

RequestGeoadd storages::redis::MockClientBase::Geoadd ( std::string key,
std::vector< GeoaddArg > point_members,
const CommandControl & command_control )
overridevirtual

◆ Geopos()

RequestGeopos storages::redis::MockClientBase::Geopos ( std::string key,
std::vector< std::string > members,
const CommandControl & command_control )
overridevirtual

◆ Georadius()

RequestGeoradius storages::redis::MockClientBase::Georadius ( std::string key,
Longitude lon,
Latitude lat,
double radius,
const GeoradiusOptions & georadius_options,
const CommandControl & command_control )
overridevirtual

◆ Geosearch() [1/4]

RequestGeosearch storages::redis::MockClientBase::Geosearch ( std::string key,
Longitude lon,
Latitude lat,
BoxWidth width,
BoxHeight height,
const GeosearchOptions & geosearch_options,
const CommandControl & command_control )
overridevirtual

◆ Geosearch() [2/4]

RequestGeosearch storages::redis::MockClientBase::Geosearch ( std::string key,
Longitude lon,
Latitude lat,
double radius,
const GeosearchOptions & geosearch_options,
const CommandControl & command_control )
overridevirtual

◆ Geosearch() [3/4]

RequestGeosearch storages::redis::MockClientBase::Geosearch ( std::string key,
std::string member,
BoxWidth width,
BoxHeight height,
const GeosearchOptions & geosearch_options,
const CommandControl & command_control )
overridevirtual

◆ Geosearch() [4/4]

RequestGeosearch storages::redis::MockClientBase::Geosearch ( std::string key,
std::string member,
double radius,
const GeosearchOptions & geosearch_options,
const CommandControl & command_control )
overridevirtual

◆ Get()

RequestGet storages::redis::MockClientBase::Get ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Getdel()

RequestGetdel storages::redis::MockClientBase::Getdel ( std::string key,
const CommandControl & command_control )
overridevirtual

Atomically returns the string value of a key and deletes the key.

Implements storages::redis::Client.

◆ Getset()

RequestGetset storages::redis::MockClientBase::Getset ( std::string key,
std::string value,
const CommandControl & command_control )
overridevirtual

◆ Hdel() [1/2]

RequestHdel storages::redis::MockClientBase::Hdel ( std::string key,
std::string field,
const CommandControl & command_control )
overridevirtual

◆ Hdel() [2/2]

RequestHdel storages::redis::MockClientBase::Hdel ( std::string key,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

◆ Hexists()

RequestHexists storages::redis::MockClientBase::Hexists ( std::string key,
std::string field,
const CommandControl & command_control )
overridevirtual

◆ Hexpire() [1/2]

RequestHexpire storages::redis::MockClientBase::Hexpire ( std::string key,
std::chrono::seconds ttl,
ExpireOptions options,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Set TTL (in seconds) on one or more hash fields with NX/XX/GT/LT modifier (HEXPIRE).

Implements storages::redis::Client.

◆ Hexpire() [2/2]

RequestHexpire storages::redis::MockClientBase::Hexpire ( std::string key,
std::chrono::seconds ttl,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Set TTL (in seconds) on one or more hash fields (HEXPIRE).

Implements storages::redis::Client.

◆ Hexpireat() [1/2]

RequestHexpire storages::redis::MockClientBase::Hexpireat ( std::string key,
std::chrono::system_clock::time_point deadline,
ExpireOptions options,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Set absolute expiration deadline on one or more hash fields with modifier (HEXPIREAT).

Implements storages::redis::Client.

◆ Hexpireat() [2/2]

RequestHexpire storages::redis::MockClientBase::Hexpireat ( std::string key,
std::chrono::system_clock::time_point deadline,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Set absolute expiration deadline on one or more hash fields (HEXPIREAT, seconds-precision).

Implements storages::redis::Client.

◆ Hexpiretime()

RequestHexpiretime storages::redis::MockClientBase::Hexpiretime ( std::string key,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Get absolute expiration unix timestamp (seconds) of one or more hash fields (HEXPIRETIME).

Implements storages::redis::Client.

◆ Hget()

RequestHget storages::redis::MockClientBase::Hget ( std::string key,
std::string field,
const CommandControl & command_control )
overridevirtual

◆ Hgetall()

RequestHgetall storages::redis::MockClientBase::Hgetall ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Hgetex() [1/2]

RequestHgetex storages::redis::MockClientBase::Hgetex ( std::string key,
HgetexOptions options,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Get the values of one or more hash fields, optionally updating their TTL.

Implements storages::redis::Client.

◆ Hgetex() [2/2]

RequestHgetex storages::redis::MockClientBase::Hgetex ( std::string key,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Get the values of one or more hash fields.

Implements storages::redis::Client.

◆ Hincrby()

RequestHincrby storages::redis::MockClientBase::Hincrby ( std::string key,
std::string field,
int64_t increment,
const CommandControl & command_control )
overridevirtual

◆ Hincrbyfloat()

RequestHincrbyfloat storages::redis::MockClientBase::Hincrbyfloat ( std::string key,
std::string field,
double increment,
const CommandControl & command_control )
overridevirtual

◆ Hkeys()

RequestHkeys storages::redis::MockClientBase::Hkeys ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Hlen()

RequestHlen storages::redis::MockClientBase::Hlen ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Hmget()

RequestHmget storages::redis::MockClientBase::Hmget ( std::string key,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

◆ Hmset()

RequestHmset storages::redis::MockClientBase::Hmset ( std::string key,
std::vector< std::pair< std::string, std::string > > field_values,
const CommandControl & command_control )
overridevirtual

◆ Hpersist()

RequestHpersist storages::redis::MockClientBase::Hpersist ( std::string key,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Remove the TTL from one or more hash fields.

Implements storages::redis::Client.

◆ Hpexpire() [1/2]

RequestHexpire storages::redis::MockClientBase::Hpexpire ( std::string key,
std::chrono::milliseconds ttl,
ExpireOptions options,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Set TTL (in milliseconds) on one or more hash fields with NX/XX/GT/LT modifier (HPEXPIRE).

Implements storages::redis::Client.

◆ Hpexpire() [2/2]

RequestHexpire storages::redis::MockClientBase::Hpexpire ( std::string key,
std::chrono::milliseconds ttl,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Set TTL (in milliseconds) on one or more hash fields (HPEXPIRE).

Implements storages::redis::Client.

◆ Hpexpireat() [1/2]

RequestHexpire storages::redis::MockClientBase::Hpexpireat ( std::string key,
std::chrono::system_clock::time_point deadline,
ExpireOptions options,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Set absolute expiration deadline on one or more hash fields with modifier (HPEXPIREAT).

Implements storages::redis::Client.

◆ Hpexpireat() [2/2]

RequestHexpire storages::redis::MockClientBase::Hpexpireat ( std::string key,
std::chrono::system_clock::time_point deadline,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Set absolute expiration deadline on one or more hash fields (HPEXPIREAT, ms-precision).

Implements storages::redis::Client.

◆ Hpexpiretime()

RequestHpexpiretime storages::redis::MockClientBase::Hpexpiretime ( std::string key,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Get absolute expiration unix timestamp (ms) of one or more hash fields (HPEXPIRETIME).

Implements storages::redis::Client.

◆ Hpttl()

RequestHpttl storages::redis::MockClientBase::Hpttl ( std::string key,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Get remaining TTL (in milliseconds) of one or more hash fields (HPTTL).

Implements storages::redis::Client.

◆ Hscan()

ScanRequest< ScanTag::kHscan > storages::redis::MockClientBase::Hscan ( std::string key,
HscanOptions options,
const CommandControl & command_control )
overridevirtual

Iterate over a collection of elements.

Sample usage:

command_control.force_request_to_master = true;
constexpr std::size_t kKeysWithSamePrefix = 100;
static const std::string kKey = "key";
for (std::size_t i = 0; i < kKeysWithSamePrefix; ++i) {
redis_client->Hset(kKey, "the_field_" + std::to_string(i), "the_value", {}).Get();
redis_client->Hset(kKey, "a_field_" + std::to_string(i), "a_value", {}).Get();
}
std::size_t matches_found = 0;
for (const auto& [field, value] : redis_client->Hscan(kKey, storages::redis::Match{"the_field*"}, command_control))
{
EXPECT_EQ(field.find("the_field"), 0) << "Does not start with 'the_field'";
EXPECT_EQ(value, "the_value");
++matches_found;
}
EXPECT_EQ(matches_found, kKeysWithSamePrefix);

Implements storages::redis::Client.

◆ Hset()

RequestHset storages::redis::MockClientBase::Hset ( std::string key,
std::string field,
std::string value,
const CommandControl & command_control )
overridevirtual

◆ Hsetex() [1/2]

RequestHsetex storages::redis::MockClientBase::Hsetex ( std::string key,
HsetexOptions options,
std::vector< HsetexFieldValue > field_values,
const CommandControl & command_control )
overridevirtual

Set one or more field/value pairs in a hash with optional FNX|FXX and TTL modifiers.

Implements storages::redis::Client.

◆ Hsetex() [2/2]

RequestHsetex storages::redis::MockClientBase::Hsetex ( std::string key,
std::vector< HsetexFieldValue > field_values,
const CommandControl & command_control )
overridevirtual

Set one or more field/value pairs in a hash without a TTL clause.

Implements storages::redis::Client.

◆ Hsetnx()

RequestHsetnx storages::redis::MockClientBase::Hsetnx ( std::string key,
std::string field,
std::string value,
const CommandControl & command_control )
overridevirtual

◆ Httl()

RequestHttl storages::redis::MockClientBase::Httl ( std::string key,
std::vector< std::string > fields,
const CommandControl & command_control )
overridevirtual

Get remaining TTL (in seconds) of one or more hash fields (HTTL).

Implements storages::redis::Client.

◆ Hvals()

RequestHvals storages::redis::MockClientBase::Hvals ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Incr()

RequestIncr storages::redis::MockClientBase::Incr ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ IsInClusterMode()

bool storages::redis::MockClientBase::IsInClusterMode ( ) const
overridevirtual

◆ IsReady() [1/2]

bool storages::redis::Client::IsReady ( WaitConnectedMode mode) const
inlineinherited

Definition at line 54 of file client.hpp.

◆ IsReady() [2/2]

bool storages::redis::MockClientBase::IsReady ( const HealthCheckParams & params) const
overridevirtual

◆ JsonGet() [1/3]

RequestJsonGet storages::redis::MockClientBase::JsonGet ( std::string key,
const CommandControl & command_control )
overridevirtual

Get the JSON value at the root path of the given key.

Implements storages::redis::Client.

◆ JsonGet() [2/3]

RequestJsonGet storages::redis::MockClientBase::JsonGet ( std::string key,
std::string path,
const CommandControl & command_control )
overridevirtual

Get the JSON value at the given path of the given key.

Implements storages::redis::Client.

◆ JsonGet() [3/3]

RequestJsonGet storages::redis::MockClientBase::JsonGet ( std::string key,
std::vector< std::string > paths,
const CommandControl & command_control )
overridevirtual

Get the JSON value at multiple paths of the given key.

Implements storages::redis::Client.

◆ JsonMget()

RequestJsonMget storages::redis::MockClientBase::JsonMget ( std::vector< std::string > keys,
std::string path,
const CommandControl & command_control )
overridevirtual

Get JSON values from multiple keys at the given path.

Implements storages::redis::Client.

◆ JsonMset()

RequestJsonMset storages::redis::MockClientBase::JsonMset ( std::vector< JsonKeyPathValue > key_path_values,
const CommandControl & command_control )
overridevirtual

Set JSON values for multiple key-path-value triplets.

Implements storages::redis::Client.

◆ JsonSet()

RequestJsonSet storages::redis::MockClientBase::JsonSet ( std::string key,
std::string path,
formats::json::Value value,
const CommandControl & command_control )
overridevirtual

Set a JSON value at the given key and path.

Implements storages::redis::Client.

◆ JsonSetIfExist()

RequestJsonSetIfExist storages::redis::MockClientBase::JsonSetIfExist ( std::string key,
std::string path,
formats::json::Value value,
const CommandControl & command_control )
overridevirtual

Set a JSON value only if the path already exists (XX).

Implements storages::redis::Client.

◆ JsonSetIfNotExist()

RequestJsonSetIfNotExist storages::redis::MockClientBase::JsonSetIfNotExist ( std::string key,
std::string path,
formats::json::Value value,
const CommandControl & command_control )
overridevirtual

Set a JSON value only if the path does not already exist (NX).

Implements storages::redis::Client.

◆ Keys()

RequestKeys storages::redis::MockClientBase::Keys ( std::string keys_pattern,
size_t shard,
const CommandControl & command_control )
overridevirtual

◆ Lindex()

RequestLindex storages::redis::MockClientBase::Lindex ( std::string key,
int64_t index,
const CommandControl & command_control )
overridevirtual

◆ Llen()

RequestLlen storages::redis::MockClientBase::Llen ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Lpop()

RequestLpop storages::redis::MockClientBase::Lpop ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Lpush() [1/2]

RequestLpush storages::redis::MockClientBase::Lpush ( std::string key,
std::string value,
const CommandControl & command_control )
overridevirtual

◆ Lpush() [2/2]

RequestLpush storages::redis::MockClientBase::Lpush ( std::string key,
std::vector< std::string > values,
const CommandControl & command_control )
overridevirtual

◆ Lpushx()

RequestLpushx storages::redis::MockClientBase::Lpushx ( std::string key,
std::string element,
const CommandControl & command_control )
overridevirtual

◆ Lrange()

RequestLrange storages::redis::MockClientBase::Lrange ( std::string key,
int64_t start,
int64_t stop,
const CommandControl & command_control )
overridevirtual

◆ Lrem()

RequestLrem storages::redis::MockClientBase::Lrem ( std::string key,
int64_t count,
std::string element,
const CommandControl & command_control )
overridevirtual

◆ Ltrim()

RequestLtrim storages::redis::MockClientBase::Ltrim ( std::string key,
int64_t start,
int64_t stop,
const CommandControl & command_control )
overridevirtual

◆ Mget()

RequestMget storages::redis::MockClientBase::Mget ( std::vector< std::string > keys,
const CommandControl & command_control )
overridevirtual

◆ Mset()

RequestMset storages::redis::MockClientBase::Mset ( std::vector< std::pair< std::string, std::string > > key_values,
const CommandControl & command_control )
overridevirtual

◆ Msetex() [1/2]

RequestMsetex storages::redis::MockClientBase::Msetex ( std::vector< std::pair< std::string, std::string > > key_values,
const CommandControl & command_control )
overridevirtual

Atomically set multiple key-value pairs, without an expiration clause.

Available since Valkey 9.1.0 and Redis 8.4.0. In cluster mode all keys must belong to the same hash slot; use a common hash tag to ensure that.

Exceptions
InvalidArgumentExceptionin cluster mode if the keys belong to different hash slots

Implements storages::redis::Client.

◆ Msetex() [2/2]

RequestMsetex storages::redis::MockClientBase::Msetex ( std::vector< std::pair< std::string, std::string > > key_values,
MsetexOptions options,
const CommandControl & command_control )
overridevirtual

Atomically set multiple key-value pairs with optional existence and TTL conditions.

Available since Valkey 9.1.0 and Redis 8.4.0. In cluster mode all keys must belong to the same hash slot; use a common hash tag to ensure that.

Exceptions
InvalidArgumentExceptionin cluster mode if the keys belong to different hash slots

Implements storages::redis::Client.

◆ Multi() [1/2]

TransactionPtr storages::redis::MockClientBase::Multi ( )
finalvirtual

◆ Multi() [2/2]

TransactionPtr storages::redis::MockClientBase::Multi ( Transaction::CheckShards check_shards)
finalvirtual

◆ Persist()

RequestPersist storages::redis::MockClientBase::Persist ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Pexpire()

RequestPexpire storages::redis::MockClientBase::Pexpire ( std::string key,
std::chrono::milliseconds ttl,
const CommandControl & command_control )
overridevirtual

◆ Ping() [1/2]

RequestPing storages::redis::MockClientBase::Ping ( size_t shard,
const CommandControl & command_control )
overridevirtual

◆ Ping() [2/2]

RequestPingMessage storages::redis::MockClientBase::Ping ( size_t shard,
std::string message,
const CommandControl & command_control )
overridevirtual

◆ Publish()

void storages::redis::MockClientBase::Publish ( std::string channel,
std::string message,
const CommandControl & command_control,
PubShard policy )
overridevirtual

◆ Rename()

RequestRename storages::redis::MockClientBase::Rename ( std::string key,
std::string new_key,
const CommandControl & command_control )
overridevirtual

◆ Rpop()

RequestRpop storages::redis::MockClientBase::Rpop ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Rpush() [1/2]

RequestRpush storages::redis::MockClientBase::Rpush ( std::string key,
std::string value,
const CommandControl & command_control )
overridevirtual

◆ Rpush() [2/2]

RequestRpush storages::redis::MockClientBase::Rpush ( std::string key,
std::vector< std::string > values,
const CommandControl & command_control )
overridevirtual

◆ Rpushx()

RequestRpushx storages::redis::MockClientBase::Rpushx ( std::string key,
std::string element,
const CommandControl & command_control )
overridevirtual

◆ Sadd() [1/2]

RequestSadd storages::redis::MockClientBase::Sadd ( std::string key,
std::string member,
const CommandControl & command_control )
overridevirtual

Add member to a set of elements.

Sample usage:

command_control.force_request_to_master = true;
constexpr std::size_t kKeysWithSamePrefix = 100;
static const std::string kKey = "key";
for (std::size_t i = 0; i < kKeysWithSamePrefix; ++i) {
redis_client->Sadd(kKey, "the_value_" + std::to_string(i), {}).Get();
redis_client->Sadd(kKey, "a_value_" + std::to_string(i), {}).Get();
}
std::size_t matches_found = 0;
for (const std::string& value : redis_client->Sscan(kKey, storages::redis::Match{"the_value*"}, command_control)) {
EXPECT_EQ(value.find("the_value"), 0) << "Does not start with 'the_value'";
++matches_found;
}
EXPECT_EQ(matches_found, kKeysWithSamePrefix);

Implements storages::redis::Client.

◆ Sadd() [2/2]

RequestSadd storages::redis::MockClientBase::Sadd ( std::string key,
std::vector< std::string > members,
const CommandControl & command_control )
overridevirtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Implements storages::redis::Client.

◆ Scan()

ScanRequest< ScanTag::kScan > storages::redis::MockClientBase::Scan ( size_t shard,
ScanOptions options,
const CommandControl & command_control )
overridevirtual

Iterate over a collection of elements.

Sample usage:

command_control.force_request_to_master = true;
constexpr std::size_t kKeysWithSamePrefix = 100;
for (std::size_t i = 0; i < kKeysWithSamePrefix; ++i) {
redis_client->Set("the_key_" + std::to_string(i), "the_value", {}).Get();
redis_client->Set("a_key_" + std::to_string(i), "a_value", {}).Get();
}
std::size_t matches_found = 0;
for (const std::string& field : redis_client->Scan(0, storages::redis::Match{"the_key*"}, command_control)) {
EXPECT_EQ(field.find("the_key"), 0) << "Does not start with 'the_key'";
++matches_found;
}
EXPECT_EQ(matches_found, kKeysWithSamePrefix);

Implements storages::redis::Client.

◆ Scard()

RequestScard storages::redis::MockClientBase::Scard ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ ScriptLoad()

RequestScriptLoad storages::redis::MockClientBase::ScriptLoad ( std::string script,
size_t shard,
const CommandControl & command_control )
overridevirtual

Load the script to the server for further execution via EvalSha() member function.

Sample usage:

auto upload_scripts = [client]() {
const std::string lua_script{R"~(
if redis.call("get",KEYS[1]) == ARGV[1] then
redis.call("del",KEYS[1])
return "del"
else
redis.call("rpush", "mismatched", KEYS[1])
return "mismatched"
end
)~"};
const std::size_t shards_count = client->ShardsCount();
std::string script_sha;
for (std::size_t i = 0; i < shards_count; ++i) {
script_sha = client->ScriptLoad(lua_script, i, {}).Get();
}
return script_sha;
};
const auto script_sha = upload_scripts();
client->Set("the_key", "the_value", {}).Get();
// ...
auto val1 = client->EvalSha<std::string>(script_sha, {"the_key"}, {"mismatched_value"}, kMasterCC).Get();
if (val1.IsNoScriptError()) {
upload_scripts();
// retry...
val1 = client->EvalSha<std::string>(script_sha, {"the_key"}, {"mismatched_value"}, kMasterCC).Get();
}
EXPECT_EQ(val1.Get(), "mismatched");
auto val2 = client->EvalSha<std::string>(script_sha, {"the_key"}, {"the_value"}, kMasterCC).Get();
if (val2.IsNoScriptError()) {
upload_scripts();
// retry...
val2 = client->EvalSha<std::string>(script_sha, {"the_key"}, {"the_value"}, kMasterCC).Get();
}
EXPECT_EQ(val2.Get(), "del");

Implements storages::redis::Client.

◆ Set() [1/2]

RequestSet storages::redis::MockClientBase::Set ( std::string key,
std::string value,
const CommandControl & command_control )
overridevirtual

◆ Set() [2/2]

RequestSet storages::redis::MockClientBase::Set ( std::string key,
std::string value,
std::chrono::milliseconds ttl,
const CommandControl & command_control )
overridevirtual

◆ SetAndGetPrevious()

RequestSetAndGetPrevious storages::redis::MockClientBase::SetAndGetPrevious ( std::string key,
std::string value,
std::chrono::milliseconds ttl,
const CommandControl & command_control )
overridevirtual

◆ Setex()

RequestSetex storages::redis::MockClientBase::Setex ( std::string key,
std::chrono::seconds seconds,
std::string value,
const CommandControl & command_control )
overridevirtual

◆ SetIfExist() [1/2]

RequestSetIfExist storages::redis::MockClientBase::SetIfExist ( std::string key,
std::string value,
const CommandControl & command_control )
overridevirtual

◆ SetIfExist() [2/2]

RequestSetIfExist storages::redis::MockClientBase::SetIfExist ( std::string key,
std::string value,
std::chrono::milliseconds ttl,
const CommandControl & command_control )
overridevirtual

◆ SetIfNotExist() [1/2]

RequestSetIfNotExist storages::redis::MockClientBase::SetIfNotExist ( std::string key,
std::string value,
const CommandControl & command_control )
overridevirtual

◆ SetIfNotExist() [2/2]

RequestSetIfNotExist storages::redis::MockClientBase::SetIfNotExist ( std::string key,
std::string value,
std::chrono::milliseconds ttl,
const CommandControl & command_control )
overridevirtual

◆ SetIfNotExistOrGet() [1/2]

RequestSetIfNotExistOrGet storages::redis::MockClientBase::SetIfNotExistOrGet ( std::string key,
std::string value,
const CommandControl & command_control )
overridevirtual

◆ SetIfNotExistOrGet() [2/2]

RequestSetIfNotExistOrGet storages::redis::MockClientBase::SetIfNotExistOrGet ( std::string key,
std::string value,
std::chrono::milliseconds ttl,
const CommandControl & command_control )
overridevirtual

◆ SetMockTransactionImplCreator()

void storages::redis::MockClientBase::SetMockTransactionImplCreator ( std::shared_ptr< MockTransactionImplCreatorBase > mock_transaction_impl_creator)
inline

Definition at line 666 of file mock_client_base.hpp.

◆ SetMockTransactionImplType()

template<typename MockTransactionImpl>
void storages::redis::MockClientBase::SetMockTransactionImplType ( )
inline

Definition at line 662 of file mock_client_base.hpp.

◆ ShardByKey()

size_t storages::redis::MockClientBase::ShardByKey ( const std::string & key) const
overridevirtual

◆ ShardsCount()

size_t storages::redis::MockClientBase::ShardsCount ( ) const
overridevirtual

◆ Sismember()

RequestSismember storages::redis::MockClientBase::Sismember ( std::string key,
std::string member,
const CommandControl & command_control )
overridevirtual

◆ Smembers()

RequestSmembers storages::redis::MockClientBase::Smembers ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Spublish()

void storages::redis::MockClientBase::Spublish ( std::string channel,
std::string message,
const CommandControl & command_control )
overridevirtual

◆ Srandmember()

RequestSrandmember storages::redis::MockClientBase::Srandmember ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Srandmembers()

RequestSrandmembers storages::redis::MockClientBase::Srandmembers ( std::string key,
int64_t count,
const CommandControl & command_control )
overridevirtual

◆ Srem() [1/2]

RequestSrem storages::redis::MockClientBase::Srem ( std::string key,
std::string member,
const CommandControl & command_control )
overridevirtual

◆ Srem() [2/2]

RequestSrem storages::redis::MockClientBase::Srem ( std::string key,
std::vector< std::string > members,
const CommandControl & command_control )
overridevirtual

◆ Sscan()

ScanRequest< ScanTag::kSscan > storages::redis::MockClientBase::Sscan ( std::string key,
SscanOptions options,
const CommandControl & command_control )
overridevirtual

Iterate over a collection of elements.

Sample usage:

command_control.force_request_to_master = true;
constexpr std::size_t kKeysWithSamePrefix = 100;
static const std::string kKey = "key";
for (std::size_t i = 0; i < kKeysWithSamePrefix; ++i) {
redis_client->Sadd(kKey, "the_value_" + std::to_string(i), {}).Get();
redis_client->Sadd(kKey, "a_value_" + std::to_string(i), {}).Get();
}
std::size_t matches_found = 0;
for (const std::string& value : redis_client->Sscan(kKey, storages::redis::Match{"the_value*"}, command_control)) {
EXPECT_EQ(value.find("the_value"), 0) << "Does not start with 'the_value'";
++matches_found;
}
EXPECT_EQ(matches_found, kKeysWithSamePrefix);

Implements storages::redis::Client.

◆ Strlen()

RequestStrlen storages::redis::MockClientBase::Strlen ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Time()

RequestTime storages::redis::MockClientBase::Time ( size_t shard,
const CommandControl & command_control )
overridevirtual

◆ Ttl()

RequestTtl storages::redis::MockClientBase::Ttl ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Type()

RequestType storages::redis::MockClientBase::Type ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Unlink() [1/2]

RequestUnlink storages::redis::MockClientBase::Unlink ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Unlink() [2/2]

RequestUnlink storages::redis::MockClientBase::Unlink ( std::vector< std::string > keys,
const CommandControl & command_control )
overridevirtual

◆ WaitConnectedOnce()

void storages::redis::MockClientBase::WaitConnectedOnce ( RedisWaitConnected wait_connected)
overridevirtual

◆ Zadd() [1/4]

RequestZadd storages::redis::MockClientBase::Zadd ( std::string key,
double score,
std::string member,
const CommandControl & command_control )
overridevirtual

◆ Zadd() [2/4]

RequestZadd storages::redis::MockClientBase::Zadd ( std::string key,
double score,
std::string member,
const ZaddOptions & options,
const CommandControl & command_control )
overridevirtual

◆ Zadd() [3/4]

RequestZadd storages::redis::MockClientBase::Zadd ( std::string key,
std::vector< std::pair< double, std::string > > scored_members,
const CommandControl & command_control )
overridevirtual

◆ Zadd() [4/4]

RequestZadd storages::redis::MockClientBase::Zadd ( std::string key,
std::vector< std::pair< double, std::string > > scored_members,
const ZaddOptions & options,
const CommandControl & command_control )
overridevirtual

◆ ZaddIncr()

RequestZaddIncr storages::redis::MockClientBase::ZaddIncr ( std::string key,
double score,
std::string member,
const CommandControl & command_control )
overridevirtual

◆ ZaddIncrExisting()

RequestZaddIncrExisting storages::redis::MockClientBase::ZaddIncrExisting ( std::string key,
double score,
std::string member,
const CommandControl & command_control )
overridevirtual

◆ Zcard()

RequestZcard storages::redis::MockClientBase::Zcard ( std::string key,
const CommandControl & command_control )
overridevirtual

◆ Zcount()

RequestZcount storages::redis::MockClientBase::Zcount ( std::string key,
double min,
double max,
const CommandControl & command_control )
overridevirtual

◆ Zrange()

RequestZrange storages::redis::MockClientBase::Zrange ( std::string key,
int64_t start,
int64_t stop,
const CommandControl & command_control )
overridevirtual

◆ Zrangebyscore() [1/4]

RequestZrangebyscore storages::redis::MockClientBase::Zrangebyscore ( std::string key,
double min,
double max,
const CommandControl & command_control )
overridevirtual

◆ Zrangebyscore() [2/4]

RequestZrangebyscore storages::redis::MockClientBase::Zrangebyscore ( std::string key,
double min,
double max,
const RangeOptions & range_options,
const CommandControl & command_control )
overridevirtual

◆ Zrangebyscore() [3/4]

RequestZrangebyscore storages::redis::MockClientBase::Zrangebyscore ( std::string key,
std::string min,
std::string max,
const CommandControl & command_control )
overridevirtual

◆ Zrangebyscore() [4/4]

RequestZrangebyscore storages::redis::MockClientBase::Zrangebyscore ( std::string key,
std::string min,
std::string max,
const RangeOptions & range_options,
const CommandControl & command_control )
overridevirtual

◆ ZrangebyscoreWithScores() [1/4]

RequestZrangebyscoreWithScores storages::redis::MockClientBase::ZrangebyscoreWithScores ( std::string key,
double min,
double max,
const CommandControl & command_control )
overridevirtual

◆ ZrangebyscoreWithScores() [2/4]

RequestZrangebyscoreWithScores storages::redis::MockClientBase::ZrangebyscoreWithScores ( std::string key,
double min,
double max,
const RangeOptions & range_options,
const CommandControl & command_control )
overridevirtual

◆ ZrangebyscoreWithScores() [3/4]

RequestZrangebyscoreWithScores storages::redis::MockClientBase::ZrangebyscoreWithScores ( std::string key,
std::string min,
std::string max,
const CommandControl & command_control )
overridevirtual

◆ ZrangebyscoreWithScores() [4/4]

RequestZrangebyscoreWithScores storages::redis::MockClientBase::ZrangebyscoreWithScores ( std::string key,
std::string min,
std::string max,
const RangeOptions & range_options,
const CommandControl & command_control )
overridevirtual

◆ ZrangeWithScores()

RequestZrangeWithScores storages::redis::MockClientBase::ZrangeWithScores ( std::string key,
int64_t start,
int64_t stop,
const CommandControl & command_control )
overridevirtual

◆ Zrem() [1/2]

RequestZrem storages::redis::MockClientBase::Zrem ( std::string key,
std::string member,
const CommandControl & command_control )
overridevirtual

◆ Zrem() [2/2]

RequestZrem storages::redis::MockClientBase::Zrem ( std::string key,
std::vector< std::string > members,
const CommandControl & command_control )
overridevirtual

◆ Zremrangebyrank()

RequestZremrangebyrank storages::redis::MockClientBase::Zremrangebyrank ( std::string key,
int64_t start,
int64_t stop,
const CommandControl & command_control )
overridevirtual

◆ Zremrangebyscore() [1/2]

RequestZremrangebyscore storages::redis::MockClientBase::Zremrangebyscore ( std::string key,
double min,
double max,
const CommandControl & command_control )
overridevirtual

◆ Zremrangebyscore() [2/2]

RequestZremrangebyscore storages::redis::MockClientBase::Zremrangebyscore ( std::string key,
std::string min,
std::string max,
const CommandControl & command_control )
overridevirtual

◆ Zscan()

ScanRequest< ScanTag::kZscan > storages::redis::MockClientBase::Zscan ( std::string key,
ZscanOptions options,
const CommandControl & command_control )
overridevirtual

Iterate over a collection of elements.

Sample usage:

command_control.force_request_to_master = true;
constexpr std::size_t kKeysWithSamePrefix = 100;
static const std::string kKey = "key";
for (std::size_t i = 0; i < kKeysWithSamePrefix; ++i) {
redis_client->Zadd(kKey, static_cast<double>(i), "the_value_" + std::to_string(i), {}).Get();
redis_client->Zadd(kKey, static_cast<double>(i), "a_value_" + std::to_string(i), {}).Get();
}
std::size_t matches_found = 0;
redis_client->Zscan(kKey, storages::redis::Match{"the_value*"}, command_control))
{
const auto& [member, score] = ms;
EXPECT_EQ(member.find("the_value"), 0) << "Does not start with 'the_value'";
++matches_found;
}
EXPECT_EQ(matches_found, kKeysWithSamePrefix);

Implements storages::redis::Client.

◆ Zscore()

RequestZscore storages::redis::MockClientBase::Zscore ( std::string key,
std::string member,
const CommandControl & command_control )
overridevirtual

The documentation for this class was generated from the following file: