diff --git a/.gitignore b/.gitignore index 86b71dadf945..20233665e368 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .DS_Store .mypy_cache .pytest_cache +.python-version *.orig /Makefile.local *.yawiki @@ -12,6 +13,7 @@ /build*/ /cmake-build-*/ CMakeLists.txt.user +CMakeUserPresets.json compile_commands.json tags static-analyzer-report diff --git a/redis/include/userver/storages/redis/client.hpp b/redis/include/userver/storages/redis/client.hpp index 6a97a5e0f4e5..d935f0b18526 100644 --- a/redis/include/userver/storages/redis/client.hpp +++ b/redis/include/userver/storages/redis/client.hpp @@ -4,7 +4,6 @@ /// @brief @copybrief storages::redis::Client #include -#include #include #include @@ -13,11 +12,11 @@ #include #include #include +#include #include #include #include #include -#include USERVER_NAMESPACE_BEGIN @@ -158,7 +157,8 @@ class Client { size_t key_index, const CommandControl& command_control ) { - return RequestGeneric{GenericCommon(std::move(command), std::move(args), key_index, command_control) + return RequestGeneric{ + GenericCommon(std::move(command), std::move(args), key_index, command_control) }; } @@ -373,9 +373,22 @@ class Client { const CommandControl& command_control ) = 0; - virtual TransactionPtr Multi() = 0; + /// @brief Atomic sequence of Redis commands (https://redis.io/docs/latest/develop/using-commands/transactions) + /// + /// @note Redis transaction implements isolation, but not + /// all-or-nothing semantics (IOW a subcommand may fail, but the following + /// subcommands will succeed). + /// Implemented via pipeline mechanism + virtual PipelinePtr Multi() = 0; + + /// @brief Atomic sequence of Redis commands (https://redis.io/docs/latest/develop/using-commands/transactions) + /// + /// @note check_shards controls if all subcommands should belong to same shard or not + virtual PipelinePtr Multi(Pipeline::CheckShards check_shards) = 0; + + virtual PipelinePtr Pipeline() = 0; - virtual TransactionPtr Multi(Transaction::CheckShards check_shards) = 0; + virtual PipelinePtr Pipeline(Pipeline::CheckShards check_shards) = 0; virtual RequestPersist Persist(std::string key, const CommandControl& command_control) = 0; diff --git a/redis/include/userver/storages/redis/impl/transaction_subrequest_data.hpp b/redis/include/userver/storages/redis/impl/pipeline_subrequest_data.hpp similarity index 68% rename from redis/include/userver/storages/redis/impl/transaction_subrequest_data.hpp rename to redis/include/userver/storages/redis/impl/pipeline_subrequest_data.hpp index fcb4cb1fe85f..19ce1b0f3701 100644 --- a/redis/include/userver/storages/redis/impl/transaction_subrequest_data.hpp +++ b/redis/include/userver/storages/redis/impl/pipeline_subrequest_data.hpp @@ -11,14 +11,12 @@ USERVER_NAMESPACE_BEGIN namespace storages::redis::impl { -[[noreturn]] void ThrowTransactionNotStarted(std::string_view description); +[[noreturn]] void ThrowPipelineNotStarted(std::string_view description); template -class TransactionSubrequestDataImpl final : public RequestDataBase { +class PipelineSubrequestDataImpl final : public RequestDataBase { public: - TransactionSubrequestDataImpl(engine::Future future) - : future_(std::move(future)) - {} + PipelineSubrequestDataImpl(engine::Future future) : future_(std::move(future)) {} void Wait() override { ThrowIfNotReady("Wait() for"); } @@ -27,7 +25,7 @@ class TransactionSubrequestDataImpl final : public RequestDataBase { return future_.get(); } - ReplyPtr GetRaw() override { throw std::logic_error("call TransactionSubrequestDataImpl::GetRaw()"); } + ReplyPtr GetRaw() override { throw std::logic_error("call PipelineSubrequestDataImpl::GetRaw()"); } engine::impl::ContextAccessor* TryGetContextAccessor() noexcept override { UASSERT_MSG(false, "Not implemented"); @@ -37,7 +35,7 @@ class TransactionSubrequestDataImpl final : public RequestDataBase { private: void ThrowIfNotReady(std::string_view description) { if (future_.wait_until(engine::Deadline::Passed()) != engine::FutureStatus::kReady) { - ThrowTransactionNotStarted(description); + ThrowPipelineNotStarted(description); } } diff --git a/redis/include/userver/storages/redis/key_type.hpp b/redis/include/userver/storages/redis/key_type.hpp index dab5c56bbaf4..c3afb1b72fda 100644 --- a/redis/include/userver/storages/redis/key_type.hpp +++ b/redis/include/userver/storages/redis/key_type.hpp @@ -12,7 +12,7 @@ namespace storages::redis { /// @brief Type of the Redis value stored by a key. /// -/// Returned by storages::redis::Client and storages::redis::Transaction from membed function `Type()` +/// Returned by storages::redis::Client and storages::redis::Pipeline from membed function `Type()` enum class KeyType { kNone, kString, kList, kSet, kZset, kHash, kStream }; KeyType ParseKeyType(std::string_view str); diff --git a/redis/include/userver/storages/redis/transaction.hpp b/redis/include/userver/storages/redis/pipeline.hpp similarity index 91% rename from redis/include/userver/storages/redis/transaction.hpp rename to redis/include/userver/storages/redis/pipeline.hpp index 5951c9687fb7..7e95a1ab7a51 100644 --- a/redis/include/userver/storages/redis/transaction.hpp +++ b/redis/include/userver/storages/redis/pipeline.hpp @@ -1,7 +1,7 @@ #pragma once -/// @file userver/storages/redis/transaction.hpp -/// @brief @copybrief storages::redis::Transaction +/// @file userver/storages/redis/pipeline.hpp +/// @brief @copybrief storages::redis::Pipeline #include #include @@ -14,27 +14,23 @@ USERVER_NAMESPACE_BEGIN namespace storages::redis { -/// @brief Atomic sequence of Redis commands (https://redis.io/topics/transactions), that is usually retrieved from -/// storages::redis::Client::Multi(). +/// @brief Sequence of Redis commands (https://redis.io/docs/latest/develop/using-commands/pipelining), that is usually +/// retrieved from storages::redis::Client::Pipeline(). /// -/// @note Redis transaction implements isolation, but not -/// all-or-nothing semantics (IOW a subcommand may fail, but the following -/// subcommands will succeed). -/// -/// Membef functions add commands to the `Transaction` object. For each added command a future-like object is returned. -/// You can get the result of each transaction's subcommand by calling `Get()` method for these objects. +/// @note Member functions add commands to the `Pipeline` object. For each added command a future-like object is +/// returned. You can get the result of each pipeline's subcommand by calling `Get()` method for these objects. /// Commands are be sent to a server after calling `Exec()` that returns `RequestExec` object. /// You should not call `Get()` method in a future-like subcommand's object /// before calling `Get()` method on `RequestExec` object. /// -/// @snippet redis/src/storages/redis/client_redistest.cpp redis transaction sample -class Transaction { +/// @snippet redis/src/storages/redis/client_redistest.cpp redis pipeline sample +class Pipeline { public: enum class CheckShards { kNo, kSame }; - virtual ~Transaction() = default; + virtual ~Pipeline() = default; - /// Finish current atomic sequence of commands and send it to a server. + /// Finish current sequence of commands and send it to a server. /// Returns 'future-like' request object. /// The data will not be set for the future-like objects for subcommands if /// `Get()` method of the returned object is not called or redis did not return an array with command responses. @@ -316,14 +312,14 @@ class Transaction { // end of redis commands }; -using TransactionPtr = std::unique_ptr; +using PipelinePtr = std::unique_ptr; -class EmptyTransactionException : public Exception { +class EmptyPipelineException : public Exception { public: using Exception::Exception; }; -class NotStartedTransactionException : public Exception { +class NotStartedPipelineException : public Exception { public: using Exception::Exception; }; diff --git a/redis/include/userver/storages/redis/request.hpp b/redis/include/userver/storages/redis/request.hpp index c41bd3eb3a51..be0081d894e6 100644 --- a/redis/include/userver/storages/redis/request.hpp +++ b/redis/include/userver/storages/redis/request.hpp @@ -1,7 +1,7 @@ #pragma once /// @file -/// @brief Valkey/Redis futures for storages::redis::Client and storages::redis::Transaction. +/// @brief Valkey/Redis futures for storages::redis::Client and storages::redis::Pipeline. #include #include @@ -26,7 +26,7 @@ class RequestScanData; /// @brief Valkey or Redis future for a non-scan and non-eval responses. /// -/// Member functions of classes storages::redis::Client and storages::redis::Transaction that do send request to the +/// Member functions of classes storages::redis::Client and storages::redis::Pipeline that do send request to the /// Redis return this type or storages::redis::ScanRequest. template class [[nodiscard]] Request final { @@ -34,14 +34,12 @@ class [[nodiscard]] Request final { using Result = ResultType; using Reply = ReplyType; - explicit Request(std::unique_ptr>&& impl) - : impl_(std::move(impl)) - {} + explicit Request(std::unique_ptr>&& impl) : impl_(std::move(impl)) {} /// Wait for the request to finish on Redis server, server or request errors (if any) are logged but not thrown. /// - /// @throws Exceptions on misuse (for example, calling Wait() on a single result from a transaction before waiting - /// for the transaction itself). + /// @throws Exceptions on misuse (for example, calling Wait() on a single result from a pipeline before waiting + /// for the pipeline itself). void Wait() { impl_->Wait(); } /// Ignore the query result and do not wait for the Redis server to finish executing it @@ -76,16 +74,14 @@ class [[nodiscard]] Request final { /// @brief Redis future for a SCAN-like responses. /// -/// Member functions of classes storages::redis::Client and storages::redis::Transaction that do send SCAN-like request +/// Member functions of classes storages::redis::Client and storages::redis::Pipeline that do send SCAN-like request /// to the Redis return this type or storages::redis::ScanRequest. template class ScanRequest final { public: using ReplyElem = typename ScanReplyElem::type; - explicit ScanRequest(std::unique_ptr>&& impl) - : impl_(std::move(impl)) - {} + explicit ScanRequest(std::unique_ptr>&& impl) : impl_(std::move(impl)) {} template > T GetAll(std::string request_description) { @@ -110,9 +106,7 @@ class ScanRequest final { using reference = value_type&; using pointer = value_type*; - explicit Iterator(ScanRequest* stream) - : stream_(stream) - { + explicit Iterator(ScanRequest* stream) : stream_(stream) { if (stream_ && !stream_->HasMore()) { stream_ = nullptr; } @@ -120,9 +114,7 @@ class ScanRequest final { class ReplyElemHolder { public: - ReplyElemHolder(value_type reply_elem) - : reply_elem_(std::move(reply_elem)) - {} + ReplyElemHolder(value_type reply_elem) : reply_elem_(std::move(reply_elem)) {} value_type& operator*() { return reply_elem_; } diff --git a/redis/src/storages/redis/client_cluster_redistest.cpp b/redis/src/storages/redis/client_cluster_redistest.cpp index 3997c812b39d..1eedc1d9aa6f 100644 --- a/redis/src/storages/redis/client_cluster_redistest.cpp +++ b/redis/src/storages/redis/client_cluster_redistest.cpp @@ -178,9 +178,9 @@ UTEST_F(RedisClusterClientTest, TransactionCrossSlot) { UASSERT_THROW(transaction->Exec(kDefaultCc).Get(), storages::redis::RequestFailedException); } -UTEST_F(RedisClusterClientTest, TransactionDistinctShards) { +UTEST_F(RedisClusterClientTest, PipelineDistinctShards) { auto client = GetClient(); - auto transaction = client->Multi(storages::redis::Transaction::CheckShards::kNo); + auto transaction = client->Pipeline(storages::redis::Pipeline::CheckShards::kNo); const size_t num_keys = 10; const int add = 100; @@ -204,33 +204,33 @@ UTEST_F(RedisClusterClientTest, Generic) { // Must abort in debug builds #ifdef NDEBUG -UTEST_F(RedisClusterClientTest, NotStartedTransactionNoExec) { +UTEST_F(RedisClusterClientTest, NotStartedPipelineNoExec) { auto client = GetClient(); - auto transaction = client->Multi(storages::redis::Transaction::CheckShards::kNo); + auto transaction = client->Pipeline(storages::redis::Pipeline::CheckShards::kNo); auto get_req = transaction->Get("key1"); auto set_req = transaction->Set("key1", "value"); - EXPECT_THROW(get_req.Get(), storages::redis::NotStartedTransactionException); - EXPECT_THROW(get_req.Wait(), storages::redis::NotStartedTransactionException); + EXPECT_THROW(get_req.Get(), storages::redis::NotStartedPipelineException); + EXPECT_THROW(get_req.Wait(), storages::redis::NotStartedPipelineException); - EXPECT_THROW(set_req.Get(), storages::redis::NotStartedTransactionException); - EXPECT_THROW(set_req.Wait(), storages::redis::NotStartedTransactionException); + EXPECT_THROW(set_req.Get(), storages::redis::NotStartedPipelineException); + EXPECT_THROW(set_req.Wait(), storages::redis::NotStartedPipelineException); } -UTEST_F(RedisClusterClientTest, NotStartedTransactionTransactionNoGet) { +UTEST_F(RedisClusterClientTest, NotStartedPipelineNoGet) { auto client = GetClient(); - auto transaction = client->Multi(storages::redis::Transaction::CheckShards::kNo); + auto transaction = client->Pipeline(storages::redis::Pipeline::CheckShards::kNo); auto get_req = transaction->Get("key2"); auto set_req = transaction->Set("key2", "value"); auto request = transaction->Exec({}); - EXPECT_THROW(get_req.Get(), storages::redis::NotStartedTransactionException); - EXPECT_THROW(get_req.Wait(), storages::redis::NotStartedTransactionException); + EXPECT_THROW(get_req.Get(), storages::redis::NotStartedPipelineException); + EXPECT_THROW(get_req.Wait(), storages::redis::NotStartedPipelineException); - EXPECT_THROW(set_req.Get(), storages::redis::NotStartedTransactionException); - EXPECT_THROW(set_req.Wait(), storages::redis::NotStartedTransactionException); + EXPECT_THROW(set_req.Get(), storages::redis::NotStartedPipelineException); + EXPECT_THROW(set_req.Wait(), storages::redis::NotStartedPipelineException); } #endif diff --git a/redis/src/storages/redis/client_impl.cpp b/redis/src/storages/redis/client_impl.cpp index 5f901659d92d..bb1415241019 100644 --- a/redis/src/storages/redis/client_impl.cpp +++ b/redis/src/storages/redis/client_impl.cpp @@ -5,6 +5,7 @@ #include #include "impl/command_control_impl.hpp" +#include "pipeline_impl.hpp" #include "request_impl.hpp" #include "transaction_impl.hpp" @@ -40,9 +41,7 @@ void DoCheckShard(size_t shard, std::optional force_shard_idx) { } // namespace -ClientImpl::ClientImpl(std::shared_ptr sentinel) - : redis_client_(std::move(sentinel)) -{} +ClientImpl::ClientImpl(std::shared_ptr sentinel) : redis_client_(std::move(sentinel)) {} void ClientImpl::WaitConnectedOnce(RedisWaitConnected wait_connected) { redis_client_->WaitConnectedOnce(wait_connected); @@ -115,8 +114,8 @@ RequestBitop ClientImpl::Bitop( RequestDbsize ClientImpl::Dbsize(size_t shard, const CommandControl& command_control) { CheckShard(shard, command_control); - return CreateRequest(MakeRequest(CmdArgs{"dbsize"}, shard, false, GetCommandControl(command_control)) - ); + return CreateRequest< + RequestDbsize>(MakeRequest(CmdArgs{"dbsize"}, shard, false, GetCommandControl(command_control))); } RequestDecr ClientImpl::Decr(std::string key, const CommandControl& command_control) { @@ -151,8 +150,8 @@ RequestUnlink ClientImpl::Unlink(std::vector keys, const CommandCon return CreateDummyRequest(std::make_shared("unlink", 0)); } auto shard = ShardByKey(keys.at(0), command_control); - return CreateRequest< - RequestUnlink>(MakeRequest(CmdArgs{"unlink", std::move(keys)}, shard, true, GetCommandControl(command_control)) + return CreateRequest( + MakeRequest(CmdArgs{"unlink", std::move(keys)}, shard, true, GetCommandControl(command_control)) ); } @@ -244,8 +243,8 @@ RequestScriptLoad ClientImpl::ScriptLoad(std::string script, size_t shard, const RequestExists ClientImpl::Exists(std::string key, const CommandControl& command_control) { auto shard = ShardByKey(key, command_control); - return CreateRequest< - RequestExists>(MakeRequest(CmdArgs{"exists", std::move(key)}, shard, false, GetCommandControl(command_control)) + return CreateRequest( + MakeRequest(CmdArgs{"exists", std::move(key)}, shard, false, GetCommandControl(command_control)) ); } @@ -254,8 +253,8 @@ RequestExists ClientImpl::Exists(std::vector keys, const CommandCon return CreateDummyRequest(std::make_shared("exists", 0)); } auto shard = ShardByKey(keys.at(0), command_control); - return CreateRequest< - RequestExists>(MakeRequest(CmdArgs{"exists", std::move(keys)}, shard, false, GetCommandControl(command_control)) + return CreateRequest( + MakeRequest(CmdArgs{"exists", std::move(keys)}, shard, false, GetCommandControl(command_control)) ); } @@ -741,16 +740,22 @@ RequestMset ClientImpl::Mset( ); } -TransactionPtr ClientImpl::Multi() { return std::make_unique(shared_from_this()); } +PipelinePtr ClientImpl::Multi() { return std::make_unique(shared_from_this()); } -TransactionPtr ClientImpl::Multi(Transaction::CheckShards check_shards) { +PipelinePtr ClientImpl::Multi(Pipeline::CheckShards check_shards) { return std::make_unique(shared_from_this(), check_shards); } +PipelinePtr ClientImpl::Pipeline() { return std::make_unique(shared_from_this()); } + +PipelinePtr ClientImpl::Pipeline(Pipeline::CheckShards check_shards) { + return std::make_unique(shared_from_this(), check_shards); +} + RequestPersist ClientImpl::Persist(std::string key, const CommandControl& command_control) { auto shard = ShardByKey(key, command_control); - return CreateRequest< - RequestPersist>(MakeRequest(CmdArgs{"persist", std::move(key)}, shard, true, GetCommandControl(command_control)) + return CreateRequest( + MakeRequest(CmdArgs{"persist", std::move(key)}, shard, true, GetCommandControl(command_control)) ); } @@ -883,9 +888,8 @@ RequestSadd ClientImpl::Sadd(std::string key, std::vector members, ScanRequest ClientImpl::Scan(size_t shard, ScanOptions options, const CommandControl& command_control) { CheckShard(shard, command_control); return ScanRequest< - ScanTag::kScan>(std::make_unique< - RequestScanData>(shared_from_this(), shard, std::move(options), command_control) - ); + ScanTag::kScan>(std::make_unique>(shared_from_this(), shard, std::move(options), command_control)); } template @@ -1089,8 +1093,8 @@ ScanRequest ClientImpl::Sscan( RequestStrlen ClientImpl::Strlen(std::string key, const CommandControl& command_control) { auto shard = ShardByKey(key, command_control); - return CreateRequest< - RequestStrlen>(MakeRequest(CmdArgs{"strlen", std::move(key)}, shard, false, GetCommandControl(command_control)) + return CreateRequest( + MakeRequest(CmdArgs{"strlen", std::move(key)}, shard, false, GetCommandControl(command_control)) ); } diff --git a/redis/src/storages/redis/client_impl.hpp b/redis/src/storages/redis/client_impl.hpp index 21afdd6cd5db..b96151a4bcd5 100644 --- a/redis/src/storages/redis/client_impl.hpp +++ b/redis/src/storages/redis/client_impl.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -11,7 +10,7 @@ #include #include -#include +#include #include "scan_reply.hpp" @@ -24,7 +23,7 @@ class Sentinel; namespace storages::redis { -class TransactionImpl; +class PipelineImpl; // NOLINTNEXTLINE(fuchsia-multiple-inheritance) class ClientImpl final : public Client, public std::enable_shared_from_this { @@ -124,11 +123,17 @@ class ClientImpl final : public Client, public std::enable_shared_from_this point_members, const CommandControl& command_control) - override; + RequestGeoadd Geoadd( + std::string key, + std::vector point_members, + const CommandControl& command_control + ) override; - RequestGeopos Geopos(std::string key, std::vector members, const CommandControl& command_control) - override; + RequestGeopos Geopos( + std::string key, + std::vector members, + const CommandControl& command_control + ) override; RequestGeoradius Georadius( std::string key, @@ -189,8 +194,12 @@ class ClientImpl final : public Client, public std::enable_shared_from_this fields, const CommandControl& command_control) - override; + RequestHmget Hmget( + std::string key, + std::vector fields, + const CommandControl& command_control + ) override; RequestHmset Hmset( std::string key, @@ -212,14 +224,25 @@ class ClientImpl final : public Client, public std::enable_shared_from_this Hscan(std::string key, HscanOptions options, const CommandControl& command_control) - override; + ScanRequest Hscan( + std::string key, + HscanOptions options, + const CommandControl& command_control + ) override; - RequestHset Hset(std::string key, std::string field, std::string value, const CommandControl& command_control) - override; + 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; + 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; @@ -235,38 +258,58 @@ class ClientImpl final : public Client, public std::enable_shared_from_this values, const CommandControl& command_control) - override; + RequestLpush Lpush( + std::string key, + std::vector 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; + 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 keys, const CommandControl& command_control) override; - RequestMset Mset(std::vector> key_values, const CommandControl& command_control) - override; + RequestMset Mset( + std::vector> key_values, + const CommandControl& command_control + ) override; - TransactionPtr Multi() override; + PipelinePtr Multi() override; - TransactionPtr Multi(Transaction::CheckShards check_shards) override; + PipelinePtr Multi(Pipeline::CheckShards check_shards) override; + + PipelinePtr Pipeline() override; + + PipelinePtr Pipeline(Pipeline::CheckShards check_shards) override; RequestPersist Persist(std::string key, const CommandControl& command_control) override; - RequestPexpire Pexpire(std::string key, std::chrono::milliseconds ttl, 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 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; @@ -276,8 +319,11 @@ class ClientImpl final : public Client, public std::enable_shared_from_this values, const CommandControl& command_control) - override; + RequestRpush Rpush( + std::string key, + std::vector values, + const CommandControl& command_control + ) override; RequestRpushx Rpushx(std::string key, std::string element, const CommandControl& command_control) override; @@ -310,8 +356,11 @@ class ClientImpl final : public Client, public std::enable_shared_from_this members, const CommandControl& command_control) override; - ScanRequest Sscan(std::string key, SscanOptions options, const CommandControl& command_control) - override; + ScanRequest Sscan( + std::string key, + SscanOptions options, + const CommandControl& command_control + ) override; RequestStrlen Strlen(std::string key, const CommandControl& command_control) override; @@ -386,8 +438,12 @@ class ClientImpl final : public Client, public std::enable_shared_from_this Zscan(std::string key, ZscanOptions options, const CommandControl& command_control) - override; + ScanRequest Zscan( + std::string key, + ZscanOptions options, + const CommandControl& command_control + ) override; RequestZscore Zscore(std::string key, std::string member, const CommandControl& command_control) override; // end of redis commands - friend class TransactionImpl; + friend class PipelineImpl; // For internal usage, don't use it impl::Sentinel& GetNative() const; diff --git a/redis/src/storages/redis/impl/cmd_args.hpp b/redis/src/storages/redis/impl/cmd_args.hpp index 790ef559d46b..1ceb2fef0b8f 100644 --- a/redis/src/storages/redis/impl/cmd_args.hpp +++ b/redis/src/storages/redis/impl/cmd_args.hpp @@ -161,6 +161,8 @@ class CmdWithArgs { class CmdArgs { public: + CmdArgs() = default; + template CmdArgs(std::string command_name, Args&&... arguments) { commands_.emplace_back(std::move(command_name), std::forward(arguments)...); @@ -207,8 +209,6 @@ class CmdArgs { } private: - CmdArgs() = default; - static constexpr std::size_t kTypicalCommandsCount = 1; boost::container::small_vector commands_; diff --git a/redis/src/storages/redis/impl/transaction_subrequest_data.cpp b/redis/src/storages/redis/impl/pipeline_subrequest_data.cpp similarity index 60% rename from redis/src/storages/redis/impl/transaction_subrequest_data.cpp rename to redis/src/storages/redis/impl/pipeline_subrequest_data.cpp index 321017f6e2d2..a7ea1d1e315f 100644 --- a/redis/src/storages/redis/impl/transaction_subrequest_data.cpp +++ b/redis/src/storages/redis/impl/pipeline_subrequest_data.cpp @@ -1,22 +1,23 @@ -#include +#include #include -#include +#include #include USERVER_NAMESPACE_BEGIN namespace storages::redis::impl { -[[noreturn]] void ThrowTransactionNotStarted(std::string_view description) { +[[noreturn]] void ThrowPipelineNotStarted(std::string_view description) { auto message = fmt::format( "Trying to {} transaction's subcommand result before calling Exec() + Get() for the entire transaction", description ); UASSERT_MSG(false, message); - throw NotStartedTransactionException(std::move(message)); + + throw NotStartedPipelineException(std::move(message)); } } // namespace storages::redis::impl diff --git a/redis/src/storages/redis/impl/request.cpp b/redis/src/storages/redis/impl/request.cpp index ba7c37e061e5..e02ae2b07637 100644 --- a/redis/src/storages/redis/impl/request.cpp +++ b/redis/src/storages/redis/impl/request.cpp @@ -18,11 +18,7 @@ namespace { class ReplyState { public: - explicit ReplyState(std::string&& span_name) - : span_(std::move(span_name)) - { - span_.Get().DetachFromCoroStack(); - } + explicit ReplyState(std::string&& span_name) : span_(std::move(span_name)) { span_.Get().DetachFromCoroStack(); } ~ReplyState() { if (!executed_) { @@ -49,7 +45,10 @@ std::string MakeSpanName(const CmdArgs& cmd_args) { } if (cmd_args.GetCommandCount() > 1) { - return "redis_multi"; + if (cmd_args.begin()->GetCommandName() == "MULTI") { + return "redis_multi"; + } + return "redis_pipeline"; } return "redis_" + cmd_args.GetCommandName(0); diff --git a/redis/src/storages/redis/impl/sentinel.hpp b/redis/src/storages/redis/impl/sentinel.hpp index 2afb6e4da9f4..b64d3df4c373 100644 --- a/redis/src/storages/redis/impl/sentinel.hpp +++ b/redis/src/storages/redis/impl/sentinel.hpp @@ -48,7 +48,7 @@ class Sentinel { /// Sentinel sends received message to callback and callback should /// notify it about the outcome. This is internal mechanism for /// communicating between our sentinel and our SubscriptionTokenImpl - enum class Outcome : uint32_t { + enum class Outcome { // everything is ok. Basically, means that message was pushed to the // SubscriptionQueue. Doesn't mean that actual user read it or processed // it or anything like that. @@ -201,7 +201,7 @@ class Sentinel { ); private: - friend class Transaction; + friend class Pipeline; std::unique_ptr impl_; const std::string shard_group_name_; diff --git a/redis/src/storages/redis/pipeline_impl.cpp b/redis/src/storages/redis/pipeline_impl.cpp new file mode 100644 index 000000000000..1f0a91239bb4 --- /dev/null +++ b/redis/src/storages/redis/pipeline_impl.cpp @@ -0,0 +1,763 @@ +#include + +#include + +#include + +#include "client_impl.hpp" +#include "request_exec_data_impl.hpp" + +USERVER_NAMESPACE_BEGIN + +namespace storages::redis { +namespace { + +RequestExec CreateExecRequest(impl::Request&& request, std::vector&& result_promises) { + return RequestExec(std::make_unique(std::move(request), std::move(result_promises))); +} + +} // namespace + +PipelineImpl::PipelineImpl(std::shared_ptr client, CheckShards check_shards) + : client_(std::move(client)), check_shards_(check_shards) {} + +RequestExec PipelineImpl::Exec(const CommandControl& command_control) { + if (!shard_) { + throw EmptyPipelineException("Can't determine shard. Empty pipeline?"); + } + + if (command_control.force_shard_idx) { + shard_ = command_control.force_shard_idx; + } + client_->CheckShardIdx(*shard_); + auto replies_to_skip = result_promises_.size() + 1; + const auto master = master_; + master_ = false; + return CreateExecRequest( + client_->MakeRequest( + std::move(cmd_args_), + *shard_, + master, + client_->GetCommandControl(command_control), + replies_to_skip + ), + std::move(result_promises_) + ); +} + +// redis commands: + +RequestAppend PipelineImpl::Append(std::string key, std::string value) { + UpdateShard(key); + return AddCmd("append", true, std::move(key), std::move(value)); +} + +RequestBitop PipelineImpl::Bitop(BitOperation op, std::string dest, std::vector srcs) { + UpdateShard(dest); + const auto operation = ToString(op); + return AddCmd("bitop", true, std::move(operation), std::move(dest), std::move(srcs)); +} + +RequestDbsize PipelineImpl::Dbsize(size_t shard) { + UpdateShard(shard); + return AddCmd("dbsize", false); +} + +RequestDecr PipelineImpl::Decr(std::string key) { + UpdateShard(key); + return AddCmd("decr", true, std::move(key)); +} + +RequestDel PipelineImpl::Del(std::string key) { + UpdateShard(key); + return AddCmd("del", true, std::move(key)); +} + +RequestDel PipelineImpl::Del(std::vector keys) { + UpdateShard(keys); + return AddCmd("del", true, std::move(keys)); +} + +RequestUnlink PipelineImpl::Unlink(std::string key) { + UpdateShard(key); + return AddCmd("unlink", true, std::move(key)); +} + +RequestUnlink PipelineImpl::Unlink(std::vector keys) { + UpdateShard(keys); + return AddCmd("unlink", true, std::move(keys)); +} + +RequestExists PipelineImpl::Exists(std::string key) { + UpdateShard(key); + return AddCmd("exists", false, std::move(key)); +} + +RequestExists PipelineImpl::Exists(std::vector keys) { + UpdateShard(keys); + return AddCmd("exists", false, std::move(keys)); +} + +RequestExpire PipelineImpl::Expire(std::string key, std::chrono::seconds ttl) { + UpdateShard(key); + return AddCmd("expire", true, std::move(key), ttl.count()); +} + +RequestExpire PipelineImpl::Expire(std::string key, std::chrono::seconds ttl, ExpireOptions options) { + UpdateShard(key); + return AddCmd("expire", true, std::move(key), ttl.count(), options); +} + +RequestGeoadd PipelineImpl::Geoadd(std::string key, GeoaddArg point_member) { + UpdateShard(key); + return AddCmd("geoadd", true, std::move(key), std::move(point_member)); +} + +RequestGeoadd PipelineImpl::Geoadd(std::string key, std::vector point_members) { + UpdateShard(key); + return AddCmd("geoadd", true, std::move(key), std::move(point_members)); +} + +RequestGeopos PipelineImpl::Geopos(std::string key, std::vector members) { + UpdateShard(key); + return AddCmd("geopos", false, std::move(key), std::move(members)); +} + +RequestGeoradius PipelineImpl::Georadius( + std::string key, + Longitude lon, + Latitude lat, + double radius, + const GeoradiusOptions& georadius_options +) { + UpdateShard(key); + return AddCmd( + "georadius_ro", + false, + std::move(key), + lon.GetUnderlying(), + lat.GetUnderlying(), + radius, + georadius_options + ); +} + +RequestGeosearch PipelineImpl::Geosearch( + std::string key, + std::string member, + double radius, + const GeosearchOptions& geosearch_options +) { + UpdateShard(key); + return AddCmd( + "geosearch", + false, + std::move(key), + "FROMMEMBER", + std::move(member), + "BYRADIUS", + radius, + geosearch_options + ); +} + +RequestGeosearch PipelineImpl::Geosearch( + std::string key, + std::string member, + BoxWidth width, + BoxHeight height, + const GeosearchOptions& geosearch_options +) { + UpdateShard(key); + return AddCmd( + "geosearch", + false, + std::move(key), + "FROMMEMBER", + std::move(member), + "BYBOX", + width.GetUnderlying(), + height.GetUnderlying(), + geosearch_options + ); +} + +RequestGeosearch PipelineImpl::Geosearch( + std::string key, + Longitude lon, + Latitude lat, + double radius, + const GeosearchOptions& geosearch_options +) { + UpdateShard(key); + return AddCmd( + "geosearch", + false, + std::move(key), + "FROMLONLAT", + lon.GetUnderlying(), + lat.GetUnderlying(), + "BYRADIUS", + radius, + geosearch_options + ); +} + +RequestGeosearch PipelineImpl::Geosearch( + std::string key, + Longitude lon, + Latitude lat, + BoxWidth width, + BoxHeight height, + const GeosearchOptions& geosearch_options +) { + UpdateShard(key); + return AddCmd( + "geosearch", + false, + std::move(key), + "FROMLONLAT", + lon.GetUnderlying(), + lat.GetUnderlying(), + "BYBOX", + width.GetUnderlying(), + height.GetUnderlying(), + geosearch_options + ); +} + +RequestGet PipelineImpl::Get(std::string key) { + UpdateShard(key); + return AddCmd("get", false, std::move(key)); +} + +RequestGetset PipelineImpl::Getset(std::string key, std::string value) { + UpdateShard(key); + return AddCmd("getset", true, std::move(key), std::move(value)); +} + +RequestHdel PipelineImpl::Hdel(std::string key, std::string field) { + UpdateShard(key); + return AddCmd("hdel", true, std::move(key), std::move(field)); +} + +RequestHdel PipelineImpl::Hdel(std::string key, std::vector fields) { + UpdateShard(key); + return AddCmd("hdel", true, std::move(key), std::move(fields)); +} + +RequestHexists PipelineImpl::Hexists(std::string key, std::string field) { + UpdateShard(key); + return AddCmd("hexists", false, std::move(key), std::move(field)); +} + +RequestHget PipelineImpl::Hget(std::string key, std::string field) { + UpdateShard(key); + return AddCmd("hget", false, std::move(key), std::move(field)); +} + +RequestHgetall PipelineImpl::Hgetall(std::string key) { + UpdateShard(key); + return AddCmd("hgetall", false, std::move(key)); +} + +RequestHincrby PipelineImpl::Hincrby(std::string key, std::string field, int64_t increment) { + UpdateShard(key); + return AddCmd("hincrby", true, std::move(key), std::move(field), increment); +} + +RequestHincrbyfloat PipelineImpl::Hincrbyfloat(std::string key, std::string field, double increment) { + UpdateShard(key); + return AddCmd("hincrbyfloat", true, std::move(key), std::move(field), increment); +} + +RequestHkeys PipelineImpl::Hkeys(std::string key) { + UpdateShard(key); + return AddCmd("hkeys", false, std::move(key)); +} + +RequestHlen PipelineImpl::Hlen(std::string key) { + UpdateShard(key); + return AddCmd("hlen", false, std::move(key)); +} + +RequestHmget PipelineImpl::Hmget(std::string key, std::vector fields) { + UpdateShard(key); + return AddCmd("hmget", false, std::move(key), std::move(fields)); +} + +RequestHmset PipelineImpl::Hmset(std::string key, std::vector> field_values) { + UpdateShard(key); + return AddCmd("hmset", true, std::move(key), std::move(field_values)); +} + +RequestHset PipelineImpl::Hset(std::string key, std::string field, std::string value) { + UpdateShard(key); + return AddCmd("hset", true, std::move(key), std::move(field), std::move(value)); +} + +RequestHsetnx PipelineImpl::Hsetnx(std::string key, std::string field, std::string value) { + UpdateShard(key); + return AddCmd("hsetnx", true, std::move(key), std::move(field), std::move(value)); +} + +RequestHvals PipelineImpl::Hvals(std::string key) { + UpdateShard(key); + return AddCmd("hvals", false, std::move(key)); +} + +RequestIncr PipelineImpl::Incr(std::string key) { + UpdateShard(key); + return AddCmd("incr", true, std::move(key)); +} + +RequestKeys PipelineImpl::Keys(std::string keys_pattern, size_t shard) { + UpdateShard(shard); + return AddCmd("keys", false, std::move(keys_pattern)); +} + +RequestLindex PipelineImpl::Lindex(std::string key, int64_t index) { + UpdateShard(key); + return AddCmd("lindex", false, std::move(key), index); +} + +RequestLlen PipelineImpl::Llen(std::string key) { + UpdateShard(key); + return AddCmd("llen", false, std::move(key)); +} + +RequestLpop PipelineImpl::Lpop(std::string key) { + UpdateShard(key); + return AddCmd("lpop", true, std::move(key)); +} + +RequestLpush PipelineImpl::Lpush(std::string key, std::string value) { + UpdateShard(key); + return AddCmd("lpush", true, std::move(key), std::move(value)); +} + +RequestLpush PipelineImpl::Lpush(std::string key, std::vector values) { + UpdateShard(key); + return AddCmd("lpush", true, std::move(key), std::move(values)); +} + +RequestLpushx PipelineImpl::Lpushx(std::string key, std::string element) { + UpdateShard(key); + return AddCmd("lpushx", true, std::move(key), std::move(element)); +} + +RequestLrange PipelineImpl::Lrange(std::string key, int64_t start, int64_t stop) { + UpdateShard(key); + return AddCmd("lrange", false, std::move(key), start, stop); +} + +RequestLrem PipelineImpl::Lrem(std::string key, int64_t count, std::string element) { + UpdateShard(key); + return AddCmd("lrem", true, std::move(key), count, std::move(element)); +} + +RequestLtrim PipelineImpl::Ltrim(std::string key, int64_t start, int64_t stop) { + UpdateShard(key); + return AddCmd("ltrim", true, std::move(key), start, stop); +} + +RequestMget PipelineImpl::Mget(std::vector keys) { + UpdateShard(keys); + return AddCmd("mget", false, std::move(keys)); +} + +RequestMset PipelineImpl::Mset(std::vector> key_values) { + UpdateShard(key_values); + return AddCmd("mset", true, std::move(key_values)); +} + +RequestPersist PipelineImpl::Persist(std::string key) { + UpdateShard(key); + return AddCmd("persist", true, std::move(key)); +} + +RequestPexpire PipelineImpl::Pexpire(std::string key, std::chrono::milliseconds ttl) { + UpdateShard(key); + return AddCmd("pexpire", true, std::move(key), ttl.count()); +} + +RequestPing PipelineImpl::Ping(size_t shard) { + UpdateShard(shard); + return AddCmd("ping", false); +} + +RequestPingMessage PipelineImpl::PingMessage(size_t shard, std::string message) { + UpdateShard(shard); + return AddCmd("ping", false, std::move(message)); +} + +RequestRename PipelineImpl::Rename(std::string key, std::string new_key) { + UpdateShard(key); + UpdateShard(new_key); + return AddCmd("rename", true, std::move(key), std::move(new_key)); +} + +RequestRpop PipelineImpl::Rpop(std::string key) { + UpdateShard(key); + return AddCmd("rpop", true, std::move(key)); +} + +RequestRpush PipelineImpl::Rpush(std::string key, std::string value) { + UpdateShard(key); + return AddCmd("rpush", true, std::move(key), std::move(value)); +} + +RequestRpush PipelineImpl::Rpush(std::string key, std::vector values) { + UpdateShard(key); + return AddCmd("rpush", true, std::move(key), std::move(values)); +} + +RequestRpushx PipelineImpl::Rpushx(std::string key, std::string element) { + UpdateShard(key); + return AddCmd("rpushx", true, std::move(key), std::move(element)); +} + +RequestSadd PipelineImpl::Sadd(std::string key, std::string member) { + UpdateShard(key); + return AddCmd("sadd", true, std::move(key), std::move(member)); +} + +RequestSadd PipelineImpl::Sadd(std::string key, std::vector members) { + UpdateShard(key); + return AddCmd("sadd", true, std::move(key), std::move(members)); +} + +RequestScard PipelineImpl::Scard(std::string key) { + UpdateShard(key); + return AddCmd("scard", false, std::move(key)); +} + +RequestSet PipelineImpl::Set(std::string key, std::string value) { + UpdateShard(key); + return AddCmd("set", true, std::move(key), std::move(value)); +} + +RequestSet PipelineImpl::Set(std::string key, std::string value, std::chrono::milliseconds ttl) { + UpdateShard(key); + return AddCmd("set", true, std::move(key), std::move(value), "PX", ttl.count()); +} + +RequestSetIfExist PipelineImpl::SetIfExist(std::string key, std::string value) { + UpdateShard(key); + return AddCmd("set", true, std::move(key), std::move(value), "XX"); +} + +RequestSetIfExist PipelineImpl::SetIfExist(std::string key, std::string value, std::chrono::milliseconds ttl) { + UpdateShard(key); + return AddCmd("set", true, std::move(key), std::move(value), "PX", ttl.count(), "XX"); +} + +RequestSetIfNotExist PipelineImpl::SetIfNotExist(std::string key, std::string value) { + UpdateShard(key); + return AddCmd("set", true, std::move(key), std::move(value), "NX"); +} + +RequestSetIfNotExist PipelineImpl::SetIfNotExist(std::string key, std::string value, std::chrono::milliseconds ttl) { + UpdateShard(key); + return AddCmd("set", true, std::move(key), std::move(value), "PX", ttl.count(), "NX"); +} + +RequestSetIfNotExistOrGet PipelineImpl::SetIfNotExistOrGet(std::string key, std::string value) { + UpdateShard(key); + return AddCmd("set", true, std::move(key), std::move(value), "NX", "GET"); +} + +RequestSetIfNotExistOrGet PipelineImpl::SetIfNotExistOrGet( + std::string key, + std::string value, + std::chrono::milliseconds ttl +) { + UpdateShard(key); + return AddCmd< + RequestSetIfNotExistOrGet>("set", true, std::move(key), std::move(value), "PX", ttl.count(), "NX", "GET"); +} + +RequestSetex PipelineImpl::Setex(std::string key, std::chrono::seconds seconds, std::string value) { + UpdateShard(key); + return AddCmd("setex", true, std::move(key), seconds.count(), std::move(value)); +} + +RequestSismember PipelineImpl::Sismember(std::string key, std::string member) { + UpdateShard(key); + return AddCmd("sismember", false, std::move(key), std::move(member)); +} + +RequestSmembers PipelineImpl::Smembers(std::string key) { + UpdateShard(key); + return AddCmd("smembers", false, std::move(key)); +} + +RequestSrandmember PipelineImpl::Srandmember(std::string key) { + UpdateShard(key); + return AddCmd("srandmember", false, std::move(key)); +} + +RequestSrandmembers PipelineImpl::Srandmembers(std::string key, int64_t count) { + UpdateShard(key); + return AddCmd("srandmember", false, std::move(key), count); +} + +RequestSrem PipelineImpl::Srem(std::string key, std::string member) { + UpdateShard(key); + return AddCmd("srem", true, std::move(key), std::move(member)); +} + +RequestSrem PipelineImpl::Srem(std::string key, std::vector members) { + UpdateShard(key); + return AddCmd("srem", true, std::move(key), std::move(members)); +} + +RequestStrlen PipelineImpl::Strlen(std::string key) { + UpdateShard(key); + return AddCmd("strlen", false, std::move(key)); +} + +RequestTime PipelineImpl::Time(size_t shard) { + UpdateShard(shard); + return AddCmd("time", false); +} + +RequestTtl PipelineImpl::Ttl(std::string key) { + UpdateShard(key); + return AddCmd("ttl", false, std::move(key)); +} + +RequestType PipelineImpl::Type(std::string key) { + UpdateShard(key); + return AddCmd("type", false, std::move(key)); +} + +RequestZadd PipelineImpl::Zadd(std::string key, double score, std::string member) { + UpdateShard(key); + return AddCmd("zadd", true, std::move(key), score, std::move(member)); +} + +RequestZadd PipelineImpl::Zadd(std::string key, double score, std::string member, const ZaddOptions& options) { + UpdateShard(key); + return AddCmd("zadd", true, std::move(key), options, score, std::move(member)); +} + +RequestZadd PipelineImpl::Zadd(std::string key, std::vector> scored_members) { + UpdateShard(key); + return AddCmd("zadd", true, std::move(key), std::move(scored_members)); +} + +RequestZadd PipelineImpl::Zadd( + std::string key, + std::vector> scored_members, + const ZaddOptions& options +) { + UpdateShard(key); + return AddCmd("zadd", true, std::move(key), options, std::move(scored_members)); +} + +RequestZaddIncr PipelineImpl::ZaddIncr(std::string key, double score, std::string member) { + UpdateShard(key); + return AddCmd("zadd", true, std::move(key), "INCR", score, std::move(member)); +} + +RequestZaddIncrExisting PipelineImpl::ZaddIncrExisting(std::string key, double score, std::string member) { + UpdateShard(key); + return AddCmd("zadd", true, std::move(key), "XX", "INCR", score, std::move(member)); +} + +RequestZcard PipelineImpl::Zcard(std::string key) { + UpdateShard(key); + return AddCmd("zcard", false, std::move(key)); +} + +RequestZcount PipelineImpl::Zcount(std::string key, double min, double max) { + UpdateShard(key); + return AddCmd("zcount", false, std::move(key), min, max); +} + +RequestZrange PipelineImpl::Zrange(std::string key, int64_t start, int64_t stop) { + UpdateShard(key); + return AddCmd("zrange", false, std::move(key), start, stop); +} + +RequestZrangeWithScores PipelineImpl::ZrangeWithScores(std::string key, int64_t start, int64_t stop) { + UpdateShard(key); + ScoreOptions with_scores{true}; + return AddCmd("zrange", false, std::move(key), start, stop, with_scores); +} + +RequestZrangebyscore PipelineImpl::Zrangebyscore(std::string key, double min, double max) { + UpdateShard(key); + return AddCmd("zrangebyscore", false, std::move(key), min, max); +} + +RequestZrangebyscore PipelineImpl::Zrangebyscore(std::string key, std::string min, std::string max) { + UpdateShard(key); + return AddCmd("zrangebyscore", false, std::move(key), std::move(min), std::move(max)); +} + +RequestZrangebyscore PipelineImpl::Zrangebyscore( + std::string key, + double min, + double max, + const RangeOptions& range_options +) { + UpdateShard(key); + return AddCmd("zrangebyscore", false, std::move(key), min, max, range_options); +} + +RequestZrangebyscore PipelineImpl::Zrangebyscore( + std::string key, + std::string min, + std::string max, + const RangeOptions& range_options +) { + UpdateShard(key); + return AddCmd< + RequestZrangebyscore>("zrangebyscore", false, std::move(key), std::move(min), std::move(max), range_options); +} + +RequestZrangebyscoreWithScores PipelineImpl::ZrangebyscoreWithScores(std::string key, double min, double max) { + UpdateShard(key); + RangeScoreOptions range_score_options{{true}, {}}; + return AddCmd< + RequestZrangebyscoreWithScores>("zrangebyscore", false, std::move(key), min, max, range_score_options); +} + +RequestZrangebyscoreWithScores PipelineImpl::ZrangebyscoreWithScores( + std::string key, + std::string min, + std::string max +) { + UpdateShard(key); + RangeScoreOptions range_score_options{{true}, {}}; + return AddCmd( + "zrangebyscore", + false, + std::move(key), + std::move(min), + std::move(max), + range_score_options + ); +} + +RequestZrangebyscoreWithScores PipelineImpl::ZrangebyscoreWithScores( + std::string key, + double min, + double max, + const RangeOptions& range_options +) { + UpdateShard(key); + RangeScoreOptions range_score_options{{true}, range_options}; + return AddCmd< + RequestZrangebyscoreWithScores>("zrangebyscore", false, std::move(key), min, max, range_score_options); +} + +RequestZrangebyscoreWithScores PipelineImpl::ZrangebyscoreWithScores( + std::string key, + std::string min, + std::string max, + const RangeOptions& range_options +) { + UpdateShard(key); + RangeScoreOptions range_score_options{{true}, range_options}; + return AddCmd( + "zrangebyscore", + false, + std::move(key), + std::move(min), + std::move(max), + range_score_options + ); +} + +RequestZrem PipelineImpl::Zrem(std::string key, std::string member) { + UpdateShard(key); + return AddCmd("zrem", true, std::move(key), std::move(member)); +} + +RequestZrem PipelineImpl::Zrem(std::string key, std::vector members) { + UpdateShard(key); + return AddCmd("zrem", true, std::move(key), std::move(members)); +} + +RequestZremrangebyrank PipelineImpl::Zremrangebyrank(std::string key, int64_t start, int64_t stop) { + UpdateShard(key); + return AddCmd("zremrangebyrank", true, std::move(key), start, stop); +} + +RequestZremrangebyscore PipelineImpl::Zremrangebyscore(std::string key, double min, double max) { + UpdateShard(key); + return AddCmd("zremrangebyscore", true, std::move(key), min, max); +} + +RequestZremrangebyscore PipelineImpl::Zremrangebyscore(std::string key, std::string min, std::string max) { + UpdateShard(key); + return AddCmd("zremrangebyscore", true, std::move(key), std::move(min), std::move(max)); +} + +RequestZscore PipelineImpl::Zscore(std::string key, std::string member) { + UpdateShard(key); + return AddCmd("zscore", false, std::move(key), std::move(member)); +} + +// end of redis commands + +void PipelineImpl::UpdateShard(const std::string& key) { + try { + UpdateShard(client_->ShardByKey(key)); + } catch (const InvalidArgumentException& ex) { + throw InvalidArgumentException(ex.what() + std::string{" for key=" + key}); + } +} + +void PipelineImpl::UpdateShard(const std::vector& keys) { + for (const auto& key : keys) { + UpdateShard(key); + } +} + +void PipelineImpl::UpdateShard(const std::vector>& key_values) { + for (const auto& key_value : key_values) { + UpdateShard(key_value.first); + } +} + +void PipelineImpl::UpdateShard(size_t shard) { + if (shard_) { + if (check_shards_ == CheckShards::kSame && *shard_ != shard) { + std::ostringstream os; + os << "storages::redis::Pipeline must deal with the same shard across " + "all the operations. Shard=" + << *shard_ + << " was detected by first command, but one of the commands used " + "shard=" + << shard; + throw InvalidArgumentException(os.str()); + } + } else { + shard_ = shard; + } +} + +template +Request PipelineImpl::DoAddCmd(To> to) { + engine::Promise promise; + Request + request(std::make_unique>(promise.get_future())); + result_promises_.emplace_back(std::move(promise), to); + return request; +} + +template +Request PipelineImpl::AddCmd(std::string command, bool master, Args&&... args) { + master_ |= master; + auto request = DoAddCmd(To{}); + cmd_args_.Then(std::move(command), std::forward(args)...); + return request; +} + +} // namespace storages::redis + +USERVER_NAMESPACE_END diff --git a/redis/src/storages/redis/pipeline_impl.hpp b/redis/src/storages/redis/pipeline_impl.hpp new file mode 100644 index 000000000000..039df3041a27 --- /dev/null +++ b/redis/src/storages/redis/pipeline_impl.hpp @@ -0,0 +1,366 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include + +#include + +USERVER_NAMESPACE_BEGIN + +namespace storages::redis { + +class ClientImpl; + +class PipelineImpl : public Pipeline { +public: + explicit PipelineImpl(std::shared_ptr client, CheckShards check_shards = CheckShards::kSame); + + RequestExec Exec(const CommandControl& command_control) override; + + class ResultPromise { + public: + template + ResultPromise(engine::Promise&& promise, To>) + : impl_(std::make_unique>(std::move(promise))) {} + ResultPromise(ResultPromise&& other) = default; + + void ProcessReply(ReplyData&& reply_data, const std::string& request_description) { + impl_->ProcessReply(std::move(reply_data), request_description); + } + + private: + class ResultPromiseImplBase { + public: + virtual ~ResultPromiseImplBase() = default; + + virtual void ProcessReply(ReplyData&& reply_data, const std::string& request_description) = 0; + }; + + template + class ResultPromiseImpl : public ResultPromiseImplBase { + public: + ResultPromiseImpl(engine::Promise&& promise) : promise_(std::move(promise)) {} + + void ProcessReply(ReplyData&& reply_data, const std::string& request_description) override { + try { + if constexpr (std::same_as) { + Parse(std::move(reply_data), request_description, To{}); + promise_.set_value(); + } else { + promise_.set_value(Parse(std::move(reply_data), request_description, To{})); + } + } catch (const std::exception&) { + promise_.set_exception(std::current_exception()); + } + } + + private: + engine::Promise promise_; + }; + + std::unique_ptr impl_; + }; + + // redis commands: + + RequestAppend Append(std::string key, std::string value) override; + + RequestBitop Bitop(BitOperation op, std::string dest, std::vector srcs) override; + + RequestDbsize Dbsize(size_t shard) override; + + RequestDecr Decr(std::string key) override; + + RequestDel Del(std::string key) override; + + RequestDel Del(std::vector keys) override; + + RequestUnlink Unlink(std::string key) override; + + RequestUnlink Unlink(std::vector keys) override; + + RequestExists Exists(std::string key) override; + + RequestExists Exists(std::vector keys) override; + + RequestExpire Expire(std::string key, std::chrono::seconds ttl) override; + + RequestExpire Expire(std::string key, std::chrono::seconds ttl, ExpireOptions options) override; + + RequestGeoadd Geoadd(std::string key, GeoaddArg point_member) override; + + RequestGeoadd Geoadd(std::string key, std::vector point_members) override; + + RequestGeopos Geopos(std::string key, std::vector members) override; + + RequestGeoradius Georadius( + std::string key, + Longitude lon, + Latitude lat, + double radius, + const GeoradiusOptions& georadius_options + ) override; + + RequestGeosearch Geosearch( + std::string key, + std::string member, + double radius, + const GeosearchOptions& geosearch_options + ) override; + + RequestGeosearch Geosearch( + std::string key, + std::string member, + BoxWidth width, + BoxHeight height, + const GeosearchOptions& geosearch_options + ) override; + + RequestGeosearch Geosearch( + std::string key, + Longitude lon, + Latitude lat, + double radius, + const GeosearchOptions& geosearch_options + ) override; + + RequestGeosearch Geosearch( + std::string key, + Longitude lon, + Latitude lat, + BoxWidth width, + BoxHeight height, + const GeosearchOptions& geosearch_options + ) override; + + RequestGet Get(std::string key) override; + + RequestGetset Getset(std::string key, std::string value) override; + + RequestHdel Hdel(std::string key, std::string field) override; + + RequestHdel Hdel(std::string key, std::vector fields) override; + + RequestHexists Hexists(std::string key, std::string field) override; + + RequestHget Hget(std::string key, std::string field) override; + + RequestHgetall Hgetall(std::string key) override; + + RequestHincrby Hincrby(std::string key, std::string field, int64_t increment) override; + + RequestHincrbyfloat Hincrbyfloat(std::string key, std::string field, double increment) override; + + RequestHkeys Hkeys(std::string key) override; + + RequestHlen Hlen(std::string key) override; + + RequestHmget Hmget(std::string key, std::vector fields) override; + + RequestHmset Hmset(std::string key, std::vector> field_values) override; + + RequestHset Hset(std::string key, std::string field, std::string value) override; + + RequestHsetnx Hsetnx(std::string key, std::string field, std::string value) override; + + RequestHvals Hvals(std::string key) override; + + RequestIncr Incr(std::string key) override; + + RequestKeys Keys(std::string keys_pattern, size_t shard) override; + + RequestLindex Lindex(std::string key, int64_t index) override; + + RequestLlen Llen(std::string key) override; + + RequestLpop Lpop(std::string key) override; + + RequestLpush Lpush(std::string key, std::string value) override; + + RequestLpush Lpush(std::string key, std::vector values) override; + + RequestLpushx Lpushx(std::string key, std::string element) override; + + RequestLrange Lrange(std::string key, int64_t start, int64_t stop) override; + + RequestLrem Lrem(std::string key, int64_t count, std::string element) override; + + RequestLtrim Ltrim(std::string key, int64_t start, int64_t stop) override; + + RequestMget Mget(std::vector keys) override; + + RequestMset Mset(std::vector> key_values) override; + + RequestPersist Persist(std::string key) override; + + RequestPexpire Pexpire(std::string key, std::chrono::milliseconds ttl) override; + + RequestPing Ping(size_t shard) override; + + RequestPingMessage PingMessage(size_t shard, std::string message) override; + + RequestRename Rename(std::string key, std::string new_key) override; + + RequestRpop Rpop(std::string key) override; + + RequestRpush Rpush(std::string key, std::string value) override; + + RequestRpush Rpush(std::string key, std::vector values) override; + + RequestRpushx Rpushx(std::string key, std::string element) override; + + RequestSadd Sadd(std::string key, std::string member) override; + + RequestSadd Sadd(std::string key, std::vector members) override; + + RequestScard Scard(std::string key) override; + + RequestSet Set(std::string key, std::string value) override; + + RequestSet Set(std::string key, std::string value, std::chrono::milliseconds ttl) override; + + RequestSetIfExist SetIfExist(std::string key, std::string value) override; + + RequestSetIfExist SetIfExist(std::string key, std::string value, std::chrono::milliseconds ttl) override; + + RequestSetIfNotExist SetIfNotExist(std::string key, std::string value) override; + + RequestSetIfNotExist SetIfNotExist(std::string key, std::string value, std::chrono::milliseconds ttl) override; + + RequestSetIfNotExistOrGet SetIfNotExistOrGet(std::string key, std::string value) override; + + RequestSetIfNotExistOrGet SetIfNotExistOrGet( + std::string key, + std::string value, + std::chrono::milliseconds ttl + ) override; + + RequestSetex Setex(std::string key, std::chrono::seconds seconds, std::string value) override; + + RequestSismember Sismember(std::string key, std::string member) override; + + RequestSmembers Smembers(std::string key) override; + + RequestSrandmember Srandmember(std::string key) override; + + RequestSrandmembers Srandmembers(std::string key, int64_t count) override; + + RequestSrem Srem(std::string key, std::string member) override; + + RequestSrem Srem(std::string key, std::vector members) override; + + RequestStrlen Strlen(std::string key) override; + + RequestTime Time(size_t shard) override; + + RequestTtl Ttl(std::string key) override; + + RequestType Type(std::string key) override; + + RequestZadd Zadd(std::string key, double score, std::string member) override; + + RequestZadd Zadd(std::string key, double score, std::string member, const ZaddOptions& options) override; + + RequestZadd Zadd(std::string key, std::vector> scored_members) override; + + RequestZadd Zadd( + std::string key, + std::vector> scored_members, + const ZaddOptions& options + ) override; + + RequestZaddIncr ZaddIncr(std::string key, double score, std::string member) override; + + RequestZaddIncrExisting ZaddIncrExisting(std::string key, double score, std::string member) override; + + RequestZcard Zcard(std::string key) override; + + RequestZcount Zcount(std::string key, double min, double max) override; + + RequestZrange Zrange(std::string key, int64_t start, int64_t stop) override; + + RequestZrangeWithScores ZrangeWithScores(std::string key, int64_t start, int64_t stop) override; + + RequestZrangebyscore Zrangebyscore(std::string key, double min, double max) override; + + RequestZrangebyscore Zrangebyscore(std::string key, std::string min, std::string max) override; + + RequestZrangebyscore Zrangebyscore( + std::string key, + double min, + double max, + const RangeOptions& range_options + ) override; + + RequestZrangebyscore Zrangebyscore( + std::string key, + std::string min, + std::string max, + const RangeOptions& range_options + ) override; + + RequestZrangebyscoreWithScores ZrangebyscoreWithScores(std::string key, double min, double max) override; + + RequestZrangebyscoreWithScores ZrangebyscoreWithScores(std::string key, std::string min, std::string max) override; + + RequestZrangebyscoreWithScores ZrangebyscoreWithScores( + std::string key, + double min, + double max, + const RangeOptions& range_options + ) override; + + RequestZrangebyscoreWithScores ZrangebyscoreWithScores( + std::string key, + std::string min, + std::string max, + const RangeOptions& range_options + ) override; + + RequestZrem Zrem(std::string key, std::string member) override; + + RequestZrem Zrem(std::string key, std::vector members) override; + + RequestZremrangebyrank Zremrangebyrank(std::string key, int64_t start, int64_t stop) override; + + RequestZremrangebyscore Zremrangebyscore(std::string key, double min, double max) override; + + RequestZremrangebyscore Zremrangebyscore(std::string key, std::string min, std::string max) override; + + RequestZscore Zscore(std::string key, std::string member) override; + + // end of redis commands + +protected: + impl::CmdArgs& CmdArgs() { return cmd_args_; } + +private: + void UpdateShard(const std::string& key); + void UpdateShard(const std::vector& keys); + void UpdateShard(const std::vector>& key_values); + void UpdateShard(size_t shard); + + template + Request DoAddCmd(To>); + + template + Request AddCmd(std::string command, bool master, Args&&... args); + + std::shared_ptr client_; + const CheckShards check_shards_; + + std::optional shard_; + + bool master_{}; + impl::CmdArgs cmd_args_; + std::vector result_promises_; +}; + +} // namespace storages::redis + +USERVER_NAMESPACE_END diff --git a/redis/src/storages/redis/request_exec_data_impl.cpp b/redis/src/storages/redis/request_exec_data_impl.cpp index 21f744225093..508b22d07969 100644 --- a/redis/src/storages/redis/request_exec_data_impl.cpp +++ b/redis/src/storages/redis/request_exec_data_impl.cpp @@ -6,11 +6,9 @@ namespace storages::redis { RequestExecDataImpl::RequestExecDataImpl( impl::Request&& request, - std::vector&& result_promises + std::vector&& result_promises ) - : request_(std::move(request)), - result_promises_(std::move(result_promises)) -{} + : request_(std::move(request)), result_promises_(std::move(result_promises)) {} void RequestExecDataImpl::Wait() noexcept { impl::Wait(request_); } diff --git a/redis/src/storages/redis/request_exec_data_impl.hpp b/redis/src/storages/redis/request_exec_data_impl.hpp index 184030c7e838..d68c0d30d6a5 100644 --- a/redis/src/storages/redis/request_exec_data_impl.hpp +++ b/redis/src/storages/redis/request_exec_data_impl.hpp @@ -1,7 +1,7 @@ #pragma once +#include "pipeline_impl.hpp" #include "request_data_impl.hpp" -#include "transaction_impl.hpp" USERVER_NAMESPACE_BEGIN @@ -9,7 +9,7 @@ namespace storages::redis { class RequestExecDataImpl final : public RequestDataBase { public: - RequestExecDataImpl(impl::Request&& request, std::vector&& result_promises); + RequestExecDataImpl(impl::Request&& request, std::vector&& result_promises); void Wait() noexcept override; @@ -26,7 +26,7 @@ class RequestExecDataImpl final : public RequestDataBase { ReplyPtr GetReply() { return request_.Get(); } impl::Request request_; - std::vector result_promises_; + std::vector result_promises_; }; } // namespace storages::redis diff --git a/redis/src/storages/redis/transaction_impl.cpp b/redis/src/storages/redis/transaction_impl.cpp index 81c6f2678589..717a3dcdbca6 100644 --- a/redis/src/storages/redis/transaction_impl.cpp +++ b/redis/src/storages/redis/transaction_impl.cpp @@ -1,765 +1,18 @@ #include -#include - -#include - -#include "client_impl.hpp" -#include "request_exec_data_impl.hpp" - USERVER_NAMESPACE_BEGIN namespace storages::redis { -namespace { - -RequestExec CreateExecRequest(impl::Request&& request, std::vector&& result_promises) { - return RequestExec(std::make_unique(std::move(request), std::move(result_promises))); -} - -} // namespace TransactionImpl::TransactionImpl(std::shared_ptr client, CheckShards check_shards) - : client_(std::move(client)), - check_shards_(check_shards), - cmd_args_({"MULTI"}) -{} - -RequestExec TransactionImpl::Exec(const CommandControl& command_control) { - if (!shard_) { - throw EmptyTransactionException("Can't determine shard. Empty transaction?"); - } - - if (command_control.force_shard_idx) { - shard_ = *command_control.force_shard_idx; - } - client_->CheckShardIdx(*shard_); - cmd_args_.Then("EXEC"); - auto replies_to_skip = result_promises_.size() + 1; - const auto master = master_; - master_ = false; - return CreateExecRequest( - client_->MakeRequest( - std::move(cmd_args_), - *shard_, - master, - client_->GetCommandControl(command_control), - replies_to_skip - ), - std::move(result_promises_) - ); -} - -// redis commands: - -RequestAppend TransactionImpl::Append(std::string key, std::string value) { - UpdateShard(key); - return AddCmd("append", true, std::move(key), std::move(value)); -} - -RequestBitop TransactionImpl::Bitop(BitOperation op, std::string dest, std::vector srcs) { - UpdateShard(dest); - const auto operation = ToString(op); - return AddCmd("bitop", true, std::move(operation), std::move(dest), std::move(srcs)); -} - -RequestDbsize TransactionImpl::Dbsize(size_t shard) { - UpdateShard(shard); - return AddCmd("dbsize", false); -} - -RequestDecr TransactionImpl::Decr(std::string key) { - UpdateShard(key); - return AddCmd("decr", true, std::move(key)); -} - -RequestDel TransactionImpl::Del(std::string key) { - UpdateShard(key); - return AddCmd("del", true, std::move(key)); -} - -RequestDel TransactionImpl::Del(std::vector keys) { - UpdateShard(keys); - return AddCmd("del", true, std::move(keys)); -} - -RequestUnlink TransactionImpl::Unlink(std::string key) { - UpdateShard(key); - return AddCmd("unlink", true, std::move(key)); -} - -RequestUnlink TransactionImpl::Unlink(std::vector keys) { - UpdateShard(keys); - return AddCmd("unlink", true, std::move(keys)); -} - -RequestExists TransactionImpl::Exists(std::string key) { - UpdateShard(key); - return AddCmd("exists", false, std::move(key)); -} - -RequestExists TransactionImpl::Exists(std::vector keys) { - UpdateShard(keys); - return AddCmd("exists", false, std::move(keys)); -} - -RequestExpire TransactionImpl::Expire(std::string key, std::chrono::seconds ttl) { - UpdateShard(key); - return AddCmd("expire", true, std::move(key), ttl.count()); -} - -RequestExpire TransactionImpl::Expire(std::string key, std::chrono::seconds ttl, ExpireOptions options) { - UpdateShard(key); - return AddCmd("expire", true, std::move(key), ttl.count(), options); -} - -RequestGeoadd TransactionImpl::Geoadd(std::string key, GeoaddArg point_member) { - UpdateShard(key); - return AddCmd("geoadd", true, std::move(key), std::move(point_member)); -} - -RequestGeoadd TransactionImpl::Geoadd(std::string key, std::vector point_members) { - UpdateShard(key); - return AddCmd("geoadd", true, std::move(key), std::move(point_members)); -} - -RequestGeopos TransactionImpl::Geopos(std::string key, std::vector members) { - UpdateShard(key); - return AddCmd("geopos", false, std::move(key), std::move(members)); -} - -RequestGeoradius TransactionImpl::Georadius( - std::string key, - Longitude lon, - Latitude lat, - double radius, - const GeoradiusOptions& georadius_options -) { - UpdateShard(key); - return AddCmd( - "georadius_ro", - false, - std::move(key), - lon.GetUnderlying(), - lat.GetUnderlying(), - radius, - georadius_options - ); -} - -RequestGeosearch TransactionImpl::Geosearch( - std::string key, - std::string member, - double radius, - const GeosearchOptions& geosearch_options -) { - UpdateShard(key); - return AddCmd( - "geosearch", - false, - std::move(key), - "FROMMEMBER", - std::move(member), - "BYRADIUS", - radius, - geosearch_options - ); -} - -RequestGeosearch TransactionImpl::Geosearch( - std::string key, - std::string member, - BoxWidth width, - BoxHeight height, - const GeosearchOptions& geosearch_options -) { - UpdateShard(key); - return AddCmd( - "geosearch", - false, - std::move(key), - "FROMMEMBER", - std::move(member), - "BYBOX", - width.GetUnderlying(), - height.GetUnderlying(), - geosearch_options - ); -} - -RequestGeosearch TransactionImpl::Geosearch( - std::string key, - Longitude lon, - Latitude lat, - double radius, - const GeosearchOptions& geosearch_options -) { - UpdateShard(key); - return AddCmd( - "geosearch", - false, - std::move(key), - "FROMLONLAT", - lon.GetUnderlying(), - lat.GetUnderlying(), - "BYRADIUS", - radius, - geosearch_options - ); -} - -RequestGeosearch TransactionImpl::Geosearch( - std::string key, - Longitude lon, - Latitude lat, - BoxWidth width, - BoxHeight height, - const GeosearchOptions& geosearch_options -) { - UpdateShard(key); - return AddCmd( - "geosearch", - false, - std::move(key), - "FROMLONLAT", - lon.GetUnderlying(), - lat.GetUnderlying(), - "BYBOX", - width.GetUnderlying(), - height.GetUnderlying(), - geosearch_options - ); -} - -RequestGet TransactionImpl::Get(std::string key) { - UpdateShard(key); - return AddCmd("get", false, std::move(key)); -} - -RequestGetset TransactionImpl::Getset(std::string key, std::string value) { - UpdateShard(key); - return AddCmd("getset", true, std::move(key), std::move(value)); -} - -RequestHdel TransactionImpl::Hdel(std::string key, std::string field) { - UpdateShard(key); - return AddCmd("hdel", true, std::move(key), std::move(field)); -} - -RequestHdel TransactionImpl::Hdel(std::string key, std::vector fields) { - UpdateShard(key); - return AddCmd("hdel", true, std::move(key), std::move(fields)); + : PipelineImpl(std::move(client), check_shards) { + CmdArgs().Then("MULTI"); } -RequestHexists TransactionImpl::Hexists(std::string key, std::string field) { - UpdateShard(key); - return AddCmd("hexists", false, std::move(key), std::move(field)); -} - -RequestHget TransactionImpl::Hget(std::string key, std::string field) { - UpdateShard(key); - return AddCmd("hget", false, std::move(key), std::move(field)); -} - -RequestHgetall TransactionImpl::Hgetall(std::string key) { - UpdateShard(key); - return AddCmd("hgetall", false, std::move(key)); -} - -RequestHincrby TransactionImpl::Hincrby(std::string key, std::string field, int64_t increment) { - UpdateShard(key); - return AddCmd("hincrby", true, std::move(key), std::move(field), increment); -} - -RequestHincrbyfloat TransactionImpl::Hincrbyfloat(std::string key, std::string field, double increment) { - UpdateShard(key); - return AddCmd("hincrbyfloat", true, std::move(key), std::move(field), increment); -} - -RequestHkeys TransactionImpl::Hkeys(std::string key) { - UpdateShard(key); - return AddCmd("hkeys", false, std::move(key)); -} - -RequestHlen TransactionImpl::Hlen(std::string key) { - UpdateShard(key); - return AddCmd("hlen", false, std::move(key)); -} - -RequestHmget TransactionImpl::Hmget(std::string key, std::vector fields) { - UpdateShard(key); - return AddCmd("hmget", false, std::move(key), std::move(fields)); -} - -RequestHmset TransactionImpl::Hmset(std::string key, std::vector> field_values) { - UpdateShard(key); - return AddCmd("hmset", true, std::move(key), std::move(field_values)); -} - -RequestHset TransactionImpl::Hset(std::string key, std::string field, std::string value) { - UpdateShard(key); - return AddCmd("hset", true, std::move(key), std::move(field), std::move(value)); -} - -RequestHsetnx TransactionImpl::Hsetnx(std::string key, std::string field, std::string value) { - UpdateShard(key); - return AddCmd("hsetnx", true, std::move(key), std::move(field), std::move(value)); -} - -RequestHvals TransactionImpl::Hvals(std::string key) { - UpdateShard(key); - return AddCmd("hvals", false, std::move(key)); -} - -RequestIncr TransactionImpl::Incr(std::string key) { - UpdateShard(key); - return AddCmd("incr", true, std::move(key)); -} - -RequestKeys TransactionImpl::Keys(std::string keys_pattern, size_t shard) { - UpdateShard(shard); - return AddCmd("keys", false, std::move(keys_pattern)); -} - -RequestLindex TransactionImpl::Lindex(std::string key, int64_t index) { - UpdateShard(key); - return AddCmd("lindex", false, std::move(key), index); -} - -RequestLlen TransactionImpl::Llen(std::string key) { - UpdateShard(key); - return AddCmd("llen", false, std::move(key)); -} - -RequestLpop TransactionImpl::Lpop(std::string key) { - UpdateShard(key); - return AddCmd("lpop", true, std::move(key)); -} - -RequestLpush TransactionImpl::Lpush(std::string key, std::string value) { - UpdateShard(key); - return AddCmd("lpush", true, std::move(key), std::move(value)); -} - -RequestLpush TransactionImpl::Lpush(std::string key, std::vector values) { - UpdateShard(key); - return AddCmd("lpush", true, std::move(key), std::move(values)); -} - -RequestLpushx TransactionImpl::Lpushx(std::string key, std::string element) { - UpdateShard(key); - return AddCmd("lpushx", true, std::move(key), std::move(element)); -} - -RequestLrange TransactionImpl::Lrange(std::string key, int64_t start, int64_t stop) { - UpdateShard(key); - return AddCmd("lrange", false, std::move(key), start, stop); -} - -RequestLrem TransactionImpl::Lrem(std::string key, int64_t count, std::string element) { - UpdateShard(key); - return AddCmd("lrem", true, std::move(key), count, std::move(element)); -} - -RequestLtrim TransactionImpl::Ltrim(std::string key, int64_t start, int64_t stop) { - UpdateShard(key); - return AddCmd("ltrim", true, std::move(key), start, stop); -} - -RequestMget TransactionImpl::Mget(std::vector keys) { - UpdateShard(keys); - return AddCmd("mget", false, std::move(keys)); -} - -RequestMset TransactionImpl::Mset(std::vector> key_values) { - UpdateShard(key_values); - return AddCmd("mset", true, std::move(key_values)); -} - -RequestPersist TransactionImpl::Persist(std::string key) { - UpdateShard(key); - return AddCmd("persist", true, std::move(key)); -} - -RequestPexpire TransactionImpl::Pexpire(std::string key, std::chrono::milliseconds ttl) { - UpdateShard(key); - return AddCmd("pexpire", true, std::move(key), ttl.count()); -} - -RequestPing TransactionImpl::Ping(size_t shard) { - UpdateShard(shard); - return AddCmd("ping", false); -} - -RequestPingMessage TransactionImpl::PingMessage(size_t shard, std::string message) { - UpdateShard(shard); - return AddCmd("ping", false, std::move(message)); -} - -RequestRename TransactionImpl::Rename(std::string key, std::string new_key) { - UpdateShard(key); - UpdateShard(new_key); - return AddCmd("rename", true, std::move(key), std::move(new_key)); -} - -RequestRpop TransactionImpl::Rpop(std::string key) { - UpdateShard(key); - return AddCmd("rpop", true, std::move(key)); -} - -RequestRpush TransactionImpl::Rpush(std::string key, std::string value) { - UpdateShard(key); - return AddCmd("rpush", true, std::move(key), std::move(value)); -} - -RequestRpush TransactionImpl::Rpush(std::string key, std::vector values) { - UpdateShard(key); - return AddCmd("rpush", true, std::move(key), std::move(values)); -} - -RequestRpushx TransactionImpl::Rpushx(std::string key, std::string element) { - UpdateShard(key); - return AddCmd("rpushx", true, std::move(key), std::move(element)); -} - -RequestSadd TransactionImpl::Sadd(std::string key, std::string member) { - UpdateShard(key); - return AddCmd("sadd", true, std::move(key), std::move(member)); -} - -RequestSadd TransactionImpl::Sadd(std::string key, std::vector members) { - UpdateShard(key); - return AddCmd("sadd", true, std::move(key), std::move(members)); -} - -RequestScard TransactionImpl::Scard(std::string key) { - UpdateShard(key); - return AddCmd("scard", false, std::move(key)); -} - -RequestSet TransactionImpl::Set(std::string key, std::string value) { - UpdateShard(key); - return AddCmd("set", true, std::move(key), std::move(value)); -} - -RequestSet TransactionImpl::Set(std::string key, std::string value, std::chrono::milliseconds ttl) { - UpdateShard(key); - return AddCmd("set", true, std::move(key), std::move(value), "PX", ttl.count()); -} - -RequestSetIfExist TransactionImpl::SetIfExist(std::string key, std::string value) { - UpdateShard(key); - return AddCmd("set", true, std::move(key), std::move(value), "XX"); -} - -RequestSetIfExist TransactionImpl::SetIfExist(std::string key, std::string value, std::chrono::milliseconds ttl) { - UpdateShard(key); - return AddCmd("set", true, std::move(key), std::move(value), "PX", ttl.count(), "XX"); -} - -RequestSetIfNotExist TransactionImpl::SetIfNotExist(std::string key, std::string value) { - UpdateShard(key); - return AddCmd("set", true, std::move(key), std::move(value), "NX"); -} - -RequestSetIfNotExist TransactionImpl::SetIfNotExist(std::string key, std::string value, std::chrono::milliseconds ttl) { - UpdateShard(key); - return AddCmd("set", true, std::move(key), std::move(value), "PX", ttl.count(), "NX"); -} - -RequestSetIfNotExistOrGet TransactionImpl::SetIfNotExistOrGet(std::string key, std::string value) { - UpdateShard(key); - return AddCmd("set", true, std::move(key), std::move(value), "NX", "GET"); -} - -RequestSetIfNotExistOrGet TransactionImpl::SetIfNotExistOrGet( - std::string key, - std::string value, - std::chrono::milliseconds ttl -) { - UpdateShard(key); - return AddCmd< - RequestSetIfNotExistOrGet>("set", true, std::move(key), std::move(value), "PX", ttl.count(), "NX", "GET"); -} - -RequestSetex TransactionImpl::Setex(std::string key, std::chrono::seconds seconds, std::string value) { - UpdateShard(key); - return AddCmd("setex", true, std::move(key), seconds.count(), std::move(value)); -} - -RequestSismember TransactionImpl::Sismember(std::string key, std::string member) { - UpdateShard(key); - return AddCmd("sismember", false, std::move(key), std::move(member)); -} - -RequestSmembers TransactionImpl::Smembers(std::string key) { - UpdateShard(key); - return AddCmd("smembers", false, std::move(key)); -} - -RequestSrandmember TransactionImpl::Srandmember(std::string key) { - UpdateShard(key); - return AddCmd("srandmember", false, std::move(key)); -} - -RequestSrandmembers TransactionImpl::Srandmembers(std::string key, int64_t count) { - UpdateShard(key); - return AddCmd("srandmember", false, std::move(key), count); -} - -RequestSrem TransactionImpl::Srem(std::string key, std::string member) { - UpdateShard(key); - return AddCmd("srem", true, std::move(key), std::move(member)); -} - -RequestSrem TransactionImpl::Srem(std::string key, std::vector members) { - UpdateShard(key); - return AddCmd("srem", true, std::move(key), std::move(members)); -} - -RequestStrlen TransactionImpl::Strlen(std::string key) { - UpdateShard(key); - return AddCmd("strlen", false, std::move(key)); -} - -RequestTime TransactionImpl::Time(size_t shard) { - UpdateShard(shard); - return AddCmd("time", false); -} - -RequestTtl TransactionImpl::Ttl(std::string key) { - UpdateShard(key); - return AddCmd("ttl", false, std::move(key)); -} - -RequestType TransactionImpl::Type(std::string key) { - UpdateShard(key); - return AddCmd("type", false, std::move(key)); -} - -RequestZadd TransactionImpl::Zadd(std::string key, double score, std::string member) { - UpdateShard(key); - return AddCmd("zadd", true, std::move(key), score, std::move(member)); -} - -RequestZadd TransactionImpl::Zadd(std::string key, double score, std::string member, const ZaddOptions& options) { - UpdateShard(key); - return AddCmd("zadd", true, std::move(key), options, score, std::move(member)); -} - -RequestZadd TransactionImpl::Zadd(std::string key, std::vector> scored_members) { - UpdateShard(key); - return AddCmd("zadd", true, std::move(key), std::move(scored_members)); -} - -RequestZadd TransactionImpl::Zadd( - std::string key, - std::vector> scored_members, - const ZaddOptions& options -) { - UpdateShard(key); - return AddCmd("zadd", true, std::move(key), options, std::move(scored_members)); -} - -RequestZaddIncr TransactionImpl::ZaddIncr(std::string key, double score, std::string member) { - UpdateShard(key); - return AddCmd("zadd", true, std::move(key), "INCR", score, std::move(member)); -} - -RequestZaddIncrExisting TransactionImpl::ZaddIncrExisting(std::string key, double score, std::string member) { - UpdateShard(key); - return AddCmd("zadd", true, std::move(key), "XX", "INCR", score, std::move(member)); -} - -RequestZcard TransactionImpl::Zcard(std::string key) { - UpdateShard(key); - return AddCmd("zcard", false, std::move(key)); -} - -RequestZcount TransactionImpl::Zcount(std::string key, double min, double max) { - UpdateShard(key); - return AddCmd("zcount", false, std::move(key), min, max); -} - -RequestZrange TransactionImpl::Zrange(std::string key, int64_t start, int64_t stop) { - UpdateShard(key); - return AddCmd("zrange", false, std::move(key), start, stop); -} - -RequestZrangeWithScores TransactionImpl::ZrangeWithScores(std::string key, int64_t start, int64_t stop) { - UpdateShard(key); - ScoreOptions with_scores{true}; - return AddCmd("zrange", false, std::move(key), start, stop, with_scores); -} - -RequestZrangebyscore TransactionImpl::Zrangebyscore(std::string key, double min, double max) { - UpdateShard(key); - return AddCmd("zrangebyscore", false, std::move(key), min, max); -} - -RequestZrangebyscore TransactionImpl::Zrangebyscore(std::string key, std::string min, std::string max) { - UpdateShard(key); - return AddCmd("zrangebyscore", false, std::move(key), std::move(min), std::move(max)); -} - -RequestZrangebyscore TransactionImpl::Zrangebyscore( - std::string key, - double min, - double max, - const RangeOptions& range_options -) { - UpdateShard(key); - return AddCmd("zrangebyscore", false, std::move(key), min, max, range_options); -} - -RequestZrangebyscore TransactionImpl::Zrangebyscore( - std::string key, - std::string min, - std::string max, - const RangeOptions& range_options -) { - UpdateShard(key); - return AddCmd< - RequestZrangebyscore>("zrangebyscore", false, std::move(key), std::move(min), std::move(max), range_options); -} - -RequestZrangebyscoreWithScores TransactionImpl::ZrangebyscoreWithScores(std::string key, double min, double max) { - UpdateShard(key); - RangeScoreOptions range_score_options{{true}, {}}; - return AddCmd< - RequestZrangebyscoreWithScores>("zrangebyscore", false, std::move(key), min, max, range_score_options); -} - -RequestZrangebyscoreWithScores TransactionImpl::ZrangebyscoreWithScores( - std::string key, - std::string min, - std::string max -) { - UpdateShard(key); - RangeScoreOptions range_score_options{{true}, {}}; - return AddCmd( - "zrangebyscore", - false, - std::move(key), - std::move(min), - std::move(max), - range_score_options - ); -} - -RequestZrangebyscoreWithScores TransactionImpl::ZrangebyscoreWithScores( - std::string key, - double min, - double max, - const RangeOptions& range_options -) { - UpdateShard(key); - RangeScoreOptions range_score_options{{true}, range_options}; - return AddCmd< - RequestZrangebyscoreWithScores>("zrangebyscore", false, std::move(key), min, max, range_score_options); -} - -RequestZrangebyscoreWithScores TransactionImpl::ZrangebyscoreWithScores( - std::string key, - std::string min, - std::string max, - const RangeOptions& range_options -) { - UpdateShard(key); - RangeScoreOptions range_score_options{{true}, range_options}; - return AddCmd( - "zrangebyscore", - false, - std::move(key), - std::move(min), - std::move(max), - range_score_options - ); -} - -RequestZrem TransactionImpl::Zrem(std::string key, std::string member) { - UpdateShard(key); - return AddCmd("zrem", true, std::move(key), std::move(member)); -} - -RequestZrem TransactionImpl::Zrem(std::string key, std::vector members) { - UpdateShard(key); - return AddCmd("zrem", true, std::move(key), std::move(members)); -} - -RequestZremrangebyrank TransactionImpl::Zremrangebyrank(std::string key, int64_t start, int64_t stop) { - UpdateShard(key); - return AddCmd("zremrangebyrank", true, std::move(key), start, stop); -} - -RequestZremrangebyscore TransactionImpl::Zremrangebyscore(std::string key, double min, double max) { - UpdateShard(key); - return AddCmd("zremrangebyscore", true, std::move(key), min, max); -} - -RequestZremrangebyscore TransactionImpl::Zremrangebyscore(std::string key, std::string min, std::string max) { - UpdateShard(key); - return AddCmd("zremrangebyscore", true, std::move(key), std::move(min), std::move(max)); -} - -RequestZscore TransactionImpl::Zscore(std::string key, std::string member) { - UpdateShard(key); - return AddCmd("zscore", false, std::move(key), std::move(member)); -} - -// end of redis commands - -void TransactionImpl::UpdateShard(const std::string& key) { - try { - UpdateShard(client_->ShardByKey(key)); - } catch (const InvalidArgumentException& ex) { - throw InvalidArgumentException(ex.what() + std::string{" for key=" + key}); - } -} - -void TransactionImpl::UpdateShard(const std::vector& keys) { - for (const auto& key : keys) { - UpdateShard(key); - } -} - -void TransactionImpl::UpdateShard(const std::vector>& key_values) { - for (const auto& key_value : key_values) { - UpdateShard(key_value.first); - } -} - -void TransactionImpl::UpdateShard(size_t shard) { - if (shard_) { - if (check_shards_ == CheckShards::kSame && *shard_ != shard) { - std::ostringstream os; - os << "storages::redis::Transaction must deal with the same shard across " - "all the operations. Shard=" - << *shard_ - << " was detected by first command, but one of the commands used " - "shard=" - << shard; - throw InvalidArgumentException(os.str()); - } - } else { - shard_ = shard; - } -} - -template -Request TransactionImpl::DoAddCmd(To> to) { - engine::Promise promise; - Request - request(std::make_unique>(promise.get_future())); - result_promises_.emplace_back(std::move(promise), to); - return request; -} +RequestExec TransactionImpl::Exec(const CommandControl& command_control) { + CmdArgs().Then("EXEC"); -template -Request TransactionImpl::AddCmd(std::string command, bool master, Args&&... args) { - master_ |= master; - auto request = DoAddCmd(To{}); - cmd_args_.Then(std::move(command), std::forward(args)...); - return request; + return PipelineImpl::Exec(command_control); } } // namespace storages::redis diff --git a/redis/src/storages/redis/transaction_impl.hpp b/redis/src/storages/redis/transaction_impl.hpp index 9018b005e3af..7ab57a0bc840 100644 --- a/redis/src/storages/redis/transaction_impl.hpp +++ b/redis/src/storages/redis/transaction_impl.hpp @@ -1,359 +1,16 @@ #pragma once -#include -#include - -#include -#include -#include -#include - -#include - -#include "request_data_impl.hpp" +#include USERVER_NAMESPACE_BEGIN namespace storages::redis { -class ClientImpl; - -class TransactionImpl final : public Transaction { +class TransactionImpl final : public PipelineImpl { public: explicit TransactionImpl(std::shared_ptr client, CheckShards check_shards = CheckShards::kSame); RequestExec Exec(const CommandControl& command_control) override; - - class ResultPromise { - public: - template - ResultPromise(engine::Promise&& promise, To>) - : impl_(std::make_unique>(std::move(promise))) - {} - ResultPromise(ResultPromise&& other) = default; - - void ProcessReply(ReplyData&& reply_data, const std::string& request_description) { - impl_->ProcessReply(std::move(reply_data), request_description); - } - - private: - class ResultPromiseImplBase { - public: - virtual ~ResultPromiseImplBase() = default; - - virtual void ProcessReply(ReplyData&& reply_data, const std::string& request_description) = 0; - }; - - template - class ResultPromiseImpl : public ResultPromiseImplBase { - public: - ResultPromiseImpl(engine::Promise&& promise) - : promise_(std::move(promise)) - {} - - void ProcessReply(ReplyData&& reply_data, const std::string& request_description) override { - try { - if constexpr (std::is_same::value) { - Parse(std::move(reply_data), request_description, To{}); - promise_.set_value(); - } else { - promise_.set_value(Parse(std::move(reply_data), request_description, To{})); - } - } catch (const std::exception&) { - promise_.set_exception(std::current_exception()); - } - } - - private: - engine::Promise promise_; - }; - - std::unique_ptr impl_; - }; - - // redis commands: - - RequestAppend Append(std::string key, std::string value) override; - - RequestBitop Bitop(BitOperation op, std::string dest, std::vector srcs) override; - - RequestDbsize Dbsize(size_t shard) override; - - RequestDecr Decr(std::string key) override; - - RequestDel Del(std::string key) override; - - RequestDel Del(std::vector keys) override; - - RequestUnlink Unlink(std::string key) override; - - RequestUnlink Unlink(std::vector keys) override; - - RequestExists Exists(std::string key) override; - - RequestExists Exists(std::vector keys) override; - - RequestExpire Expire(std::string key, std::chrono::seconds ttl) override; - - RequestExpire Expire(std::string key, std::chrono::seconds ttl, ExpireOptions options) override; - - RequestGeoadd Geoadd(std::string key, GeoaddArg point_member) override; - - RequestGeoadd Geoadd(std::string key, std::vector point_members) override; - - RequestGeopos Geopos(std::string key, std::vector members) override; - - RequestGeoradius Georadius( - std::string key, - Longitude lon, - Latitude lat, - double radius, - const GeoradiusOptions& georadius_options - ) override; - - RequestGeosearch Geosearch( - std::string key, - std::string member, - double radius, - const GeosearchOptions& geosearch_options - ) override; - - RequestGeosearch Geosearch( - std::string key, - std::string member, - BoxWidth width, - BoxHeight height, - const GeosearchOptions& geosearch_options - ) override; - - RequestGeosearch Geosearch( - std::string key, - Longitude lon, - Latitude lat, - double radius, - const GeosearchOptions& geosearch_options - ) override; - - RequestGeosearch Geosearch( - std::string key, - Longitude lon, - Latitude lat, - BoxWidth width, - BoxHeight height, - const GeosearchOptions& geosearch_options - ) override; - - RequestGet Get(std::string key) override; - - RequestGetset Getset(std::string key, std::string value) override; - - RequestHdel Hdel(std::string key, std::string field) override; - - RequestHdel Hdel(std::string key, std::vector fields) override; - - RequestHexists Hexists(std::string key, std::string field) override; - - RequestHget Hget(std::string key, std::string field) override; - - RequestHgetall Hgetall(std::string key) override; - - RequestHincrby Hincrby(std::string key, std::string field, int64_t increment) override; - - RequestHincrbyfloat Hincrbyfloat(std::string key, std::string field, double increment) override; - - RequestHkeys Hkeys(std::string key) override; - - RequestHlen Hlen(std::string key) override; - - RequestHmget Hmget(std::string key, std::vector fields) override; - - RequestHmset Hmset(std::string key, std::vector> field_values) override; - - RequestHset Hset(std::string key, std::string field, std::string value) override; - - RequestHsetnx Hsetnx(std::string key, std::string field, std::string value) override; - - RequestHvals Hvals(std::string key) override; - - RequestIncr Incr(std::string key) override; - - RequestKeys Keys(std::string keys_pattern, size_t shard) override; - - RequestLindex Lindex(std::string key, int64_t index) override; - - RequestLlen Llen(std::string key) override; - - RequestLpop Lpop(std::string key) override; - - RequestLpush Lpush(std::string key, std::string value) override; - - RequestLpush Lpush(std::string key, std::vector values) override; - - RequestLpushx Lpushx(std::string key, std::string element) override; - - RequestLrange Lrange(std::string key, int64_t start, int64_t stop) override; - - RequestLrem Lrem(std::string key, int64_t count, std::string element) override; - - RequestLtrim Ltrim(std::string key, int64_t start, int64_t stop) override; - - RequestMget Mget(std::vector keys) override; - - RequestMset Mset(std::vector> key_values) override; - - RequestPersist Persist(std::string key) override; - - RequestPexpire Pexpire(std::string key, std::chrono::milliseconds ttl) override; - - RequestPing Ping(size_t shard) override; - - RequestPingMessage PingMessage(size_t shard, std::string message) override; - - RequestRename Rename(std::string key, std::string new_key) override; - - RequestRpop Rpop(std::string key) override; - - RequestRpush Rpush(std::string key, std::string value) override; - - RequestRpush Rpush(std::string key, std::vector values) override; - - RequestRpushx Rpushx(std::string key, std::string element) override; - - RequestSadd Sadd(std::string key, std::string member) override; - - RequestSadd Sadd(std::string key, std::vector members) override; - - RequestScard Scard(std::string key) override; - - RequestSet Set(std::string key, std::string value) override; - - RequestSet Set(std::string key, std::string value, std::chrono::milliseconds ttl) override; - - RequestSetIfExist SetIfExist(std::string key, std::string value) override; - - RequestSetIfExist SetIfExist(std::string key, std::string value, std::chrono::milliseconds ttl) override; - - RequestSetIfNotExist SetIfNotExist(std::string key, std::string value) override; - - RequestSetIfNotExist SetIfNotExist(std::string key, std::string value, std::chrono::milliseconds ttl) override; - - RequestSetIfNotExistOrGet SetIfNotExistOrGet(std::string key, std::string value) override; - - RequestSetIfNotExistOrGet SetIfNotExistOrGet(std::string key, std::string value, std::chrono::milliseconds ttl) - override; - - RequestSetex Setex(std::string key, std::chrono::seconds seconds, std::string value) override; - - RequestSismember Sismember(std::string key, std::string member) override; - - RequestSmembers Smembers(std::string key) override; - - RequestSrandmember Srandmember(std::string key) override; - - RequestSrandmembers Srandmembers(std::string key, int64_t count) override; - - RequestSrem Srem(std::string key, std::string member) override; - - RequestSrem Srem(std::string key, std::vector members) override; - - RequestStrlen Strlen(std::string key) override; - - RequestTime Time(size_t shard) override; - - RequestTtl Ttl(std::string key) override; - - RequestType Type(std::string key) override; - - RequestZadd Zadd(std::string key, double score, std::string member) override; - - RequestZadd Zadd(std::string key, double score, std::string member, const ZaddOptions& options) override; - - RequestZadd Zadd(std::string key, std::vector> scored_members) override; - - RequestZadd Zadd( - std::string key, - std::vector> scored_members, - const ZaddOptions& options - ) override; - - RequestZaddIncr ZaddIncr(std::string key, double score, std::string member) override; - - RequestZaddIncrExisting ZaddIncrExisting(std::string key, double score, std::string member) override; - - RequestZcard Zcard(std::string key) override; - - RequestZcount Zcount(std::string key, double min, double max) override; - - RequestZrange Zrange(std::string key, int64_t start, int64_t stop) override; - - RequestZrangeWithScores ZrangeWithScores(std::string key, int64_t start, int64_t stop) override; - - RequestZrangebyscore Zrangebyscore(std::string key, double min, double max) override; - - RequestZrangebyscore Zrangebyscore(std::string key, std::string min, std::string max) override; - - RequestZrangebyscore Zrangebyscore(std::string key, double min, double max, const RangeOptions& range_options) - override; - - RequestZrangebyscore Zrangebyscore( - std::string key, - std::string min, - std::string max, - const RangeOptions& range_options - ) override; - - RequestZrangebyscoreWithScores ZrangebyscoreWithScores(std::string key, double min, double max) override; - - RequestZrangebyscoreWithScores ZrangebyscoreWithScores(std::string key, std::string min, std::string max) override; - - RequestZrangebyscoreWithScores ZrangebyscoreWithScores( - std::string key, - double min, - double max, - const RangeOptions& range_options - ) override; - - RequestZrangebyscoreWithScores ZrangebyscoreWithScores( - std::string key, - std::string min, - std::string max, - const RangeOptions& range_options - ) override; - - RequestZrem Zrem(std::string key, std::string member) override; - - RequestZrem Zrem(std::string key, std::vector members) override; - - RequestZremrangebyrank Zremrangebyrank(std::string key, int64_t start, int64_t stop) override; - - RequestZremrangebyscore Zremrangebyscore(std::string key, double min, double max) override; - - RequestZremrangebyscore Zremrangebyscore(std::string key, std::string min, std::string max) override; - - RequestZscore Zscore(std::string key, std::string member) override; - - // end of redis commands - -private: - void UpdateShard(const std::string& key); - void UpdateShard(const std::vector& keys); - void UpdateShard(const std::vector>& key_values); - void UpdateShard(size_t shard); - - template - Request DoAddCmd(To>); - - template - Request AddCmd(std::string command, bool master, Args&&... args); - - std::shared_ptr client_; - const CheckShards check_shards_; - - std::optional shard_; - - bool master_{}; - impl::CmdArgs cmd_args_; - std::vector result_promises_; }; } // namespace storages::redis diff --git a/redis/src/storages/redis/transaction_redistest.cpp b/redis/src/storages/redis/transaction_redistest.cpp index f4d329fd5c24..8602ec42c5b9 100644 --- a/redis/src/storages/redis/transaction_redistest.cpp +++ b/redis/src/storages/redis/transaction_redistest.cpp @@ -32,7 +32,7 @@ class RedisClientTransactionTest : public RedisClientTest { } private: - storages::redis::TransactionPtr transaction_; + storages::redis::PipelinePtr transaction_; }; } // namespace @@ -270,6 +270,8 @@ UTEST_P(RedisExpireOptionsTransactionTest, ExpireOptionsTest) { case ExpireReply::kTimeoutWasSet: EXPECT_EQ(Get(client->Ttl("mykey")).GetExpire().count(), new_expire); break; + default: + ADD_FAILURE(); } } @@ -1024,14 +1026,14 @@ UTEST_F(RedisClientTransactionTest, NotStartedTransactionNoExec) { auto get_req = transaction->Get("key1"); auto set_req = transaction->Set("key1", "value"); - EXPECT_THROW(get_req.Wait(), storages::redis::NotStartedTransactionException); - EXPECT_THROW(get_req.Get(), storages::redis::NotStartedTransactionException); + EXPECT_THROW(get_req.Wait(), storages::redis::NotStartedPipelineException); + EXPECT_THROW(get_req.Get(), storages::redis::NotStartedPipelineException); - EXPECT_THROW(set_req.Wait(), storages::redis::NotStartedTransactionException); - EXPECT_THROW(set_req.Get(), storages::redis::NotStartedTransactionException); + EXPECT_THROW(set_req.Wait(), storages::redis::NotStartedPipelineException); + EXPECT_THROW(set_req.Get(), storages::redis::NotStartedPipelineException); } -UTEST_F(RedisClientTransactionTest, NotStartedTransactionTransactionNoGet) { +UTEST_F(RedisClientTransactionTest, NotStartedPipelineNoGet) { auto client = GetClient(); auto transaction = client->Multi(); @@ -1039,11 +1041,11 @@ UTEST_F(RedisClientTransactionTest, NotStartedTransactionTransactionNoGet) { auto set_req = transaction->Set("key2", "value"); auto request = transaction->Exec({}); - EXPECT_THROW(get_req.Wait(), storages::redis::NotStartedTransactionException); - EXPECT_THROW(get_req.Get(), storages::redis::NotStartedTransactionException); + EXPECT_THROW(get_req.Wait(), storages::redis::NotStartedPipelineException); + EXPECT_THROW(get_req.Get(), storages::redis::NotStartedPipelineException); - EXPECT_THROW(set_req.Wait(), storages::redis::NotStartedTransactionException); - EXPECT_THROW(set_req.Get(), storages::redis::NotStartedTransactionException); + EXPECT_THROW(set_req.Wait(), storages::redis::NotStartedPipelineException); + EXPECT_THROW(set_req.Get(), storages::redis::NotStartedPipelineException); } #endif diff --git a/redis/testing/include/userver/storages/redis/mock_client_base.hpp b/redis/testing/include/userver/storages/redis/mock_client_base.hpp index e810e5b2dca0..1c0dc79e8527 100644 --- a/redis/testing/include/userver/storages/redis/mock_client_base.hpp +++ b/redis/testing/include/userver/storages/redis/mock_client_base.hpp @@ -13,9 +13,9 @@ #include #include +#include #include -#include -#include +#include USERVER_NAMESPACE_BEGIN @@ -123,11 +123,17 @@ class MockClientBase : public Client, public std::enable_shared_from_this point_members, const CommandControl& command_control) - override; + RequestGeoadd Geoadd( + std::string key, + std::vector point_members, + const CommandControl& command_control + ) override; - RequestGeopos Geopos(std::string key, std::vector members, const CommandControl& command_control) - override; + RequestGeopos Geopos( + std::string key, + std::vector members, + const CommandControl& command_control + ) override; RequestGeoradius Georadius( std::string key, @@ -188,8 +194,12 @@ class MockClientBase : public Client, public std::enable_shared_from_this fields, const CommandControl& command_control) - override; + RequestHmget Hmget( + std::string key, + std::vector fields, + const CommandControl& command_control + ) override; RequestHmset Hmset( std::string key, @@ -211,14 +224,25 @@ class MockClientBase : public Client, public std::enable_shared_from_this Hscan(std::string key, HscanOptions options, const CommandControl& command_control) - override; + ScanRequest Hscan( + std::string key, + HscanOptions options, + const CommandControl& command_control + ) override; - RequestHset Hset(std::string key, std::string field, std::string value, const CommandControl& command_control) - override; + 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; + 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; @@ -234,34 +258,50 @@ class MockClientBase : public Client, public std::enable_shared_from_this values, const CommandControl& command_control) - override; + RequestLpush Lpush( + std::string key, + std::vector 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; + 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 keys, const CommandControl& command_control) override; - RequestMset Mset(std::vector> key_values, const CommandControl& command_control) - override; + RequestMset Mset( + std::vector> key_values, + const CommandControl& command_control + ) override; RequestPersist Persist(std::string key, const CommandControl& command_control) override; - RequestPexpire Pexpire(std::string key, std::chrono::milliseconds ttl, 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 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; @@ -271,8 +311,11 @@ class MockClientBase : public Client, public std::enable_shared_from_this values, const CommandControl& command_control) - override; + RequestRpush Rpush( + std::string key, + std::vector values, + const CommandControl& command_control + ) override; RequestRpushx Rpushx(std::string key, std::string element, const CommandControl& command_control) override; @@ -302,8 +345,11 @@ class MockClientBase : public Client, public std::enable_shared_from_this members, const CommandControl& command_control) override; - ScanRequest Sscan(std::string key, SscanOptions options, const CommandControl& command_control) - override; + ScanRequest Sscan( + std::string key, + SscanOptions options, + const CommandControl& command_control + ) override; RequestStrlen Strlen(std::string key, const CommandControl& command_control) override; @@ -378,8 +427,12 @@ class MockClientBase : public Client, public std::enable_shared_from_this Zscan(std::string key, ZscanOptions options, const CommandControl& command_control) - override; + ScanRequest Zscan( + std::string key, + ZscanOptions options, + const CommandControl& command_control + ) override; RequestZscore Zscore(std::string key, std::string member, const CommandControl& command_control) override; // end of redis commands - TransactionPtr Multi() final; + PipelinePtr Multi() final; + + PipelinePtr Multi(Pipeline::CheckShards check_shards) final; + + PipelinePtr Pipeline() final; - TransactionPtr Multi(Transaction::CheckShards check_shards) final; + PipelinePtr Pipeline(Pipeline::CheckShards check_shards) final; - class MockTransactionImplCreatorBase { + class MockPipelineImplCreatorBase { public: - virtual ~MockTransactionImplCreatorBase() = default; + virtual ~MockPipelineImplCreatorBase() = default; - virtual std::unique_ptr operator()() const = 0; + virtual std::unique_ptr operator()() const = 0; }; - template - void SetMockTransactionImplType() { - mock_transaction_impl_creator_ = std::make_shared>(); + template + void SetMockPipelineImplType() { + mock_pipeline_impl_creator_ = std::make_shared>(); } - void SetMockTransactionImplCreator(std::shared_ptr mock_transaction_impl_creator) { - mock_transaction_impl_creator_ = std::move(mock_transaction_impl_creator); + void SetMockPipelineImplCreator(std::shared_ptr mock_pipeline_impl_creator) { + mock_pipeline_impl_creator_ = std::move(mock_pipeline_impl_creator); } MockClientBase( - std::shared_ptr mock_transaction_impl_creator, + std::shared_ptr mock_pipeline_impl_creator, std::optional force_shard_idx ); private: - template - class MockTransactionImplCreator : public MockTransactionImplCreatorBase { + template + class MockPipelineImplCreator : public MockPipelineImplCreatorBase { public: - std::unique_ptr operator()() const override { - return std::make_unique(); + std::unique_ptr operator()() const override { + return std::make_unique(); } }; - std::shared_ptr mock_transaction_impl_creator_; + std::shared_ptr mock_pipeline_impl_creator_; std::optional force_shard_idx_; }; diff --git a/redis/testing/include/userver/storages/redis/mock_transaction.hpp b/redis/testing/include/userver/storages/redis/mock_pipeline.hpp similarity index 94% rename from redis/testing/include/userver/storages/redis/mock_transaction.hpp rename to redis/testing/include/userver/storages/redis/mock_pipeline.hpp index 2357a2bb048f..b387b4d3a071 100644 --- a/redis/testing/include/userver/storages/redis/mock_transaction.hpp +++ b/redis/testing/include/userver/storages/redis/mock_pipeline.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include USERVER_NAMESPACE_BEGIN @@ -9,15 +9,15 @@ namespace storages::redis { class MockClientBase; -class MockTransaction final : public Transaction { +class MockPipeline final : public Pipeline { public: - MockTransaction( + MockPipeline( std::shared_ptr client, - std::unique_ptr impl, + std::unique_ptr impl, CheckShards check_shards = CheckShards::kSame ); - ~MockTransaction() override; + ~MockPipeline() override; RequestExec Exec(const CommandControl& command_control) override; @@ -189,8 +189,11 @@ class MockTransaction final : public Transaction { RequestSetIfNotExistOrGet SetIfNotExistOrGet(std::string key, std::string value) override; - RequestSetIfNotExistOrGet SetIfNotExistOrGet(std::string key, std::string value, std::chrono::milliseconds ttl) - override; + RequestSetIfNotExistOrGet SetIfNotExistOrGet( + std::string key, + std::string value, + std::chrono::milliseconds ttl + ) override; RequestSetex Setex(std::string key, std::chrono::seconds seconds, std::string value) override; @@ -242,8 +245,12 @@ class MockTransaction final : public Transaction { RequestZrangebyscore Zrangebyscore(std::string key, std::string min, std::string max) override; - RequestZrangebyscore Zrangebyscore(std::string key, double min, double max, const RangeOptions& range_options) - override; + RequestZrangebyscore Zrangebyscore( + std::string key, + double min, + double max, + const RangeOptions& range_options + ) override; RequestZrangebyscore Zrangebyscore( std::string key, @@ -301,7 +308,7 @@ class MockTransaction final : public Transaction { std::shared_ptr client_; const CheckShards check_shards_; - std::unique_ptr impl_; + std::unique_ptr impl_; std::optional shard_; std::vector> result_promises_; diff --git a/redis/testing/include/userver/storages/redis/mock_transaction_impl_base.hpp b/redis/testing/include/userver/storages/redis/mock_pipeline_impl_base.hpp similarity index 98% rename from redis/testing/include/userver/storages/redis/mock_transaction_impl_base.hpp rename to redis/testing/include/userver/storages/redis/mock_pipeline_impl_base.hpp index 4a1eb221abeb..dfa1ade57463 100644 --- a/redis/testing/include/userver/storages/redis/mock_transaction_impl_base.hpp +++ b/redis/testing/include/userver/storages/redis/mock_pipeline_impl_base.hpp @@ -2,15 +2,15 @@ #include -#include +#include USERVER_NAMESPACE_BEGIN namespace storages::redis { -class MockTransactionImplBase { +class MockPipelineImplBase { public: - virtual ~MockTransactionImplBase() = default; + virtual ~MockPipelineImplBase() = default; // redis commands: diff --git a/redis/testing/src/storages/redis/mock_client_base.cpp b/redis/testing/src/storages/redis/mock_client_base.cpp index 61e46cedeaf8..4d7b138f34a2 100644 --- a/redis/testing/src/storages/redis/mock_client_base.cpp +++ b/redis/testing/src/storages/redis/mock_client_base.cpp @@ -2,7 +2,7 @@ #include -#include +#include USERVER_NAMESPACE_BEGIN @@ -15,16 +15,13 @@ constexpr std::string_view kNotMocked{"Redis method is not mocked"}; } MockClientBase::MockClientBase() - : mock_transaction_impl_creator_(std::make_unique>()) -{} + : mock_pipeline_impl_creator_(std::make_unique>()) {} MockClientBase::MockClientBase( - std::shared_ptr mock_transaction_impl_creator, + std::shared_ptr mock_pipeline_impl_creator, std::optional force_shard_idx ) - : mock_transaction_impl_creator_(std::move(mock_transaction_impl_creator)), - force_shard_idx_(force_shard_idx) -{} + : mock_pipeline_impl_creator_(std::move(mock_pipeline_impl_creator)), force_shard_idx_(force_shard_idx) {} MockClientBase::~MockClientBase() = default; @@ -910,14 +907,25 @@ RequestZscore MockClientBase::Zscore( // end of redis commands -TransactionPtr MockClientBase::Multi() { - UASSERT_MSG(!!mock_transaction_impl_creator_, "MockTransactionImpl type not set"); - return std::make_unique(shared_from_this(), (*mock_transaction_impl_creator_)()); +// TODO(): probably use another creator here +PipelinePtr MockClientBase::Multi() { + UASSERT_MSG(!!mock_pipeline_impl_creator_, "MockPipelineImpl type not set"); + return std::make_unique(shared_from_this(), (*mock_pipeline_impl_creator_)()); } -TransactionPtr MockClientBase::Multi(Transaction::CheckShards check_shards) { - UASSERT_MSG(!!mock_transaction_impl_creator_, "MockTransactionImpl type not set"); - return std::make_unique(shared_from_this(), (*mock_transaction_impl_creator_)(), check_shards); +PipelinePtr MockClientBase::Multi(Pipeline::CheckShards check_shards) { + UASSERT_MSG(!!mock_pipeline_impl_creator_, "MockPipelineImpl type not set"); + return std::make_unique(shared_from_this(), (*mock_pipeline_impl_creator_)(), check_shards); +} + +PipelinePtr MockClientBase::Pipeline() { + UASSERT_MSG(!!mock_pipeline_impl_creator_, "MockPipelineImpl type not set"); + return std::make_unique(shared_from_this(), (*mock_pipeline_impl_creator_)()); +} + +PipelinePtr MockClientBase::Pipeline(Pipeline::CheckShards check_shards) { + UASSERT_MSG(!!mock_pipeline_impl_creator_, "MockPipelineImpl type not set"); + return std::make_unique(shared_from_this(), (*mock_pipeline_impl_creator_)(), check_shards); } } // namespace storages::redis diff --git a/redis/testing/src/storages/redis/mock_transaction.cpp b/redis/testing/src/storages/redis/mock_pipeline.cpp similarity index 62% rename from redis/testing/src/storages/redis/mock_transaction.cpp rename to redis/testing/src/storages/redis/mock_pipeline.cpp index e5f97078ea52..e3eab377c4ce 100644 --- a/redis/testing/src/storages/redis/mock_transaction.cpp +++ b/redis/testing/src/storages/redis/mock_pipeline.cpp @@ -1,22 +1,21 @@ -#include +#include #include #include -#include +#include #include USERVER_NAMESPACE_BEGIN namespace storages::redis { -class MockTransaction::ResultPromise { +class MockPipeline::ResultPromise { public: template ResultPromise(engine::Promise&& promise, Request&& subrequest) - : impl_(std::make_unique>(std::move(promise), std::move(subrequest))) - {} + : impl_(std::make_unique>(std::move(promise), std::move(subrequest))) {} ResultPromise(ResultPromise&& other) = default; @@ -34,13 +33,11 @@ class MockTransaction::ResultPromise { class ResultPromiseImpl : public ResultPromiseImplBase { public: ResultPromiseImpl(engine::Promise&& promise, Request&& subrequest) - : promise_(std::move(promise)), - subrequest_(std::move(subrequest)) - {} + : promise_(std::move(promise)), subrequest_(std::move(subrequest)) {} void ProcessReply(const std::string& request_description) override { try { - if constexpr (std::is_same::value) { + if constexpr (std::same_as) { subrequest_.Get(request_description); promise_.set_value(); } else { @@ -61,11 +58,10 @@ class MockTransaction::ResultPromise { std::unique_ptr impl_; }; -class MockTransaction::MockRequestExecDataImpl final : public RequestDataBase { +class MockPipeline::MockRequestExecDataImpl final : public RequestDataBase { public: MockRequestExecDataImpl(std::vector>&& result_promises) - : result_promises_(std::move(result_promises)) - {} + : result_promises_(std::move(result_promises)) {} void Wait() override {} @@ -89,24 +85,21 @@ class MockTransaction::MockRequestExecDataImpl final : public RequestDataBase> result_promises_; }; -MockTransaction::MockTransaction( +MockPipeline::MockPipeline( std::shared_ptr client, - std::unique_ptr impl, + std::unique_ptr impl, CheckShards check_shards ) - : client_(std::move(client)), - check_shards_(check_shards), - impl_(std::move(impl)) -{} + : client_(std::move(client)), check_shards_(check_shards), impl_(std::move(impl)) {} -MockTransaction::~MockTransaction() = default; +MockPipeline::~MockPipeline() = default; -RequestExec MockTransaction::Exec(const CommandControl& command_control) { +RequestExec MockPipeline::Exec(const CommandControl& command_control) { if (!shard_) { - throw EmptyTransactionException("Can't determine shard. Empty transaction?"); + throw EmptyPipelineException("Can't determine shard. Empty pipeline?"); } if (command_control.force_shard_idx) { - shard_ = *command_control.force_shard_idx; + shard_ = command_control.force_shard_idx; } client_->CheckShardIdx(*shard_); return CreateMockExecRequest(); @@ -114,82 +107,82 @@ RequestExec MockTransaction::Exec(const CommandControl& command_control) { // redis commands: -RequestAppend MockTransaction::Append(std::string key, std::string value) { +RequestAppend MockPipeline::Append(std::string key, std::string value) { UpdateShard(key); return AddSubrequest(impl_->Append(std::move(key), std::move(value))); } -RequestBitop MockTransaction::Bitop(BitOperation op, std::string dest, std::vector srcs) { +RequestBitop MockPipeline::Bitop(BitOperation op, std::string dest, std::vector srcs) { UpdateShard(dest); return AddSubrequest(impl_->Bitop(op, std::move(dest), std::move(srcs))); } -RequestDbsize MockTransaction::Dbsize(size_t shard) { +RequestDbsize MockPipeline::Dbsize(size_t shard) { UpdateShard(shard); return AddSubrequest(impl_->Dbsize(shard)); } -RequestDecr MockTransaction::Decr(std::string key) { +RequestDecr MockPipeline::Decr(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Decr(std::move(key))); } -RequestDel MockTransaction::Del(std::string key) { +RequestDel MockPipeline::Del(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Del(std::move(key))); } -RequestDel MockTransaction::Del(std::vector keys) { +RequestDel MockPipeline::Del(std::vector keys) { UpdateShard(keys); return AddSubrequest(impl_->Del(std::move(keys))); } -RequestUnlink MockTransaction::Unlink(std::string key) { +RequestUnlink MockPipeline::Unlink(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Unlink(std::move(key))); } -RequestUnlink MockTransaction::Unlink(std::vector keys) { +RequestUnlink MockPipeline::Unlink(std::vector keys) { UpdateShard(keys); return AddSubrequest(impl_->Unlink(std::move(keys))); } -RequestExists MockTransaction::Exists(std::string key) { +RequestExists MockPipeline::Exists(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Exists(std::move(key))); } -RequestExists MockTransaction::Exists(std::vector keys) { +RequestExists MockPipeline::Exists(std::vector keys) { UpdateShard(keys); return AddSubrequest(impl_->Exists(std::move(keys))); } -RequestExpire MockTransaction::Expire(std::string key, std::chrono::seconds ttl) { +RequestExpire MockPipeline::Expire(std::string key, std::chrono::seconds ttl) { UpdateShard(key); return AddSubrequest(impl_->Expire(std::move(key), ttl)); } -RequestExpire MockTransaction::Expire(std::string key, std::chrono::seconds ttl, ExpireOptions options) { +RequestExpire MockPipeline::Expire(std::string key, std::chrono::seconds ttl, ExpireOptions options) { UpdateShard(key); return AddSubrequest(impl_->Expire(std::move(key), ttl, options)); } -RequestGeoadd MockTransaction::Geoadd(std::string key, GeoaddArg point_member) { +RequestGeoadd MockPipeline::Geoadd(std::string key, GeoaddArg point_member) { UpdateShard(key); return AddSubrequest(impl_->Geoadd(std::move(key), point_member)); } -RequestGeoadd MockTransaction::Geoadd(std::string key, std::vector point_members) { +RequestGeoadd MockPipeline::Geoadd(std::string key, std::vector point_members) { UpdateShard(key); return AddSubrequest(impl_->Geoadd(std::move(key), std::move(point_members))); } -RequestGeopos MockTransaction::Geopos(std::string key, std::vector members) { +RequestGeopos MockPipeline::Geopos(std::string key, std::vector members) { UpdateShard(key); return AddSubrequest(impl_->Geopos(std::move(key), std::move(members))); } -RequestGeoradius MockTransaction::Georadius( +RequestGeoradius MockPipeline::Georadius( std::string key, Longitude lon, Latitude lat, @@ -200,7 +193,7 @@ RequestGeoradius MockTransaction::Georadius( return AddSubrequest(impl_->Georadius(std::move(key), lon, lat, radius, georadius_options)); } -RequestGeosearch MockTransaction::Geosearch( +RequestGeosearch MockPipeline::Geosearch( std::string key, std::string member, double radius, @@ -210,7 +203,7 @@ RequestGeosearch MockTransaction::Geosearch( return AddSubrequest(impl_->Geosearch(std::move(key), std::move(member), radius, geosearch_options)); } -RequestGeosearch MockTransaction::Geosearch( +RequestGeosearch MockPipeline::Geosearch( std::string key, std::string member, BoxWidth width, @@ -221,7 +214,7 @@ RequestGeosearch MockTransaction::Geosearch( return AddSubrequest(impl_->Geosearch(std::move(key), std::move(member), width, height, geosearch_options)); } -RequestGeosearch MockTransaction::Geosearch( +RequestGeosearch MockPipeline::Geosearch( std::string key, Longitude lon, Latitude lat, @@ -232,7 +225,7 @@ RequestGeosearch MockTransaction::Geosearch( return AddSubrequest(impl_->Geosearch(std::move(key), lon, lat, radius, geosearch_options)); } -RequestGeosearch MockTransaction::Geosearch( +RequestGeosearch MockPipeline::Geosearch( std::string key, Longitude lon, Latitude lat, @@ -244,248 +237,248 @@ RequestGeosearch MockTransaction::Geosearch( return AddSubrequest(impl_->Geosearch(std::move(key), lon, lat, width, height, geosearch_options)); } -RequestGet MockTransaction::Get(std::string key) { +RequestGet MockPipeline::Get(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Get(std::move(key))); } -RequestGetset MockTransaction::Getset(std::string key, std::string value) { +RequestGetset MockPipeline::Getset(std::string key, std::string value) { UpdateShard(key); return AddSubrequest(impl_->Getset(std::move(key), std::move(value))); } -RequestHdel MockTransaction::Hdel(std::string key, std::string field) { +RequestHdel MockPipeline::Hdel(std::string key, std::string field) { UpdateShard(key); return AddSubrequest(impl_->Hdel(std::move(key), std::move(field))); } -RequestHdel MockTransaction::Hdel(std::string key, std::vector fields) { +RequestHdel MockPipeline::Hdel(std::string key, std::vector fields) { UpdateShard(key); return AddSubrequest(impl_->Hdel(std::move(key), std::move(fields))); } -RequestHexists MockTransaction::Hexists(std::string key, std::string field) { +RequestHexists MockPipeline::Hexists(std::string key, std::string field) { UpdateShard(key); return AddSubrequest(impl_->Hexists(std::move(key), std::move(field))); } -RequestHget MockTransaction::Hget(std::string key, std::string field) { +RequestHget MockPipeline::Hget(std::string key, std::string field) { UpdateShard(key); return AddSubrequest(impl_->Hget(std::move(key), std::move(field))); } -RequestHgetall MockTransaction::Hgetall(std::string key) { +RequestHgetall MockPipeline::Hgetall(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Hgetall(std::move(key))); } -RequestHincrby MockTransaction::Hincrby(std::string key, std::string field, int64_t increment) { +RequestHincrby MockPipeline::Hincrby(std::string key, std::string field, int64_t increment) { UpdateShard(key); return AddSubrequest(impl_->Hincrby(std::move(key), std::move(field), increment)); } -RequestHincrbyfloat MockTransaction::Hincrbyfloat(std::string key, std::string field, double increment) { +RequestHincrbyfloat MockPipeline::Hincrbyfloat(std::string key, std::string field, double increment) { UpdateShard(key); return AddSubrequest(impl_->Hincrbyfloat(std::move(key), std::move(field), increment)); } -RequestHkeys MockTransaction::Hkeys(std::string key) { +RequestHkeys MockPipeline::Hkeys(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Hkeys(std::move(key))); } -RequestHlen MockTransaction::Hlen(std::string key) { +RequestHlen MockPipeline::Hlen(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Hlen(std::move(key))); } -RequestHmget MockTransaction::Hmget(std::string key, std::vector fields) { +RequestHmget MockPipeline::Hmget(std::string key, std::vector fields) { UpdateShard(key); return AddSubrequest(impl_->Hmget(std::move(key), std::move(fields))); } -RequestHmset MockTransaction::Hmset(std::string key, std::vector> field_values) { +RequestHmset MockPipeline::Hmset(std::string key, std::vector> field_values) { UpdateShard(key); return AddSubrequest(impl_->Hmset(std::move(key), std::move(field_values))); } -RequestHset MockTransaction::Hset(std::string key, std::string field, std::string value) { +RequestHset MockPipeline::Hset(std::string key, std::string field, std::string value) { UpdateShard(key); return AddSubrequest(impl_->Hset(std::move(key), std::move(field), std::move(value))); } -RequestHsetnx MockTransaction::Hsetnx(std::string key, std::string field, std::string value) { +RequestHsetnx MockPipeline::Hsetnx(std::string key, std::string field, std::string value) { UpdateShard(key); return AddSubrequest(impl_->Hsetnx(std::move(key), std::move(field), std::move(value))); } -RequestHvals MockTransaction::Hvals(std::string key) { +RequestHvals MockPipeline::Hvals(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Hvals(std::move(key))); } -RequestIncr MockTransaction::Incr(std::string key) { +RequestIncr MockPipeline::Incr(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Incr(std::move(key))); } -RequestKeys MockTransaction::Keys(std::string keys_pattern, size_t shard) { +RequestKeys MockPipeline::Keys(std::string keys_pattern, size_t shard) { UpdateShard(shard); return AddSubrequest(impl_->Keys(std::move(keys_pattern), shard)); } -RequestLindex MockTransaction::Lindex(std::string key, int64_t index) { +RequestLindex MockPipeline::Lindex(std::string key, int64_t index) { UpdateShard(key); return AddSubrequest(impl_->Lindex(std::move(key), index)); } -RequestLlen MockTransaction::Llen(std::string key) { +RequestLlen MockPipeline::Llen(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Llen(std::move(key))); } -RequestLpop MockTransaction::Lpop(std::string key) { +RequestLpop MockPipeline::Lpop(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Lpop(std::move(key))); } -RequestLpush MockTransaction::Lpush(std::string key, std::string value) { +RequestLpush MockPipeline::Lpush(std::string key, std::string value) { UpdateShard(key); return AddSubrequest(impl_->Lpush(std::move(key), std::move(value))); } -RequestLpush MockTransaction::Lpush(std::string key, std::vector values) { +RequestLpush MockPipeline::Lpush(std::string key, std::vector values) { UpdateShard(key); return AddSubrequest(impl_->Lpush(std::move(key), std::move(values))); } -RequestLpushx MockTransaction::Lpushx(std::string key, std::string element) { +RequestLpushx MockPipeline::Lpushx(std::string key, std::string element) { UpdateShard(key); return AddSubrequest(impl_->Lpushx(std::move(key), std::move(element))); } -RequestLrange MockTransaction::Lrange(std::string key, int64_t start, int64_t stop) { +RequestLrange MockPipeline::Lrange(std::string key, int64_t start, int64_t stop) { UpdateShard(key); return AddSubrequest(impl_->Lrange(std::move(key), start, stop)); } -RequestLrem MockTransaction::Lrem(std::string key, int64_t count, std::string element) { +RequestLrem MockPipeline::Lrem(std::string key, int64_t count, std::string element) { UpdateShard(key); return AddSubrequest(impl_->Lrem(std::move(key), count, std::move(element))); } -RequestLtrim MockTransaction::Ltrim(std::string key, int64_t start, int64_t stop) { +RequestLtrim MockPipeline::Ltrim(std::string key, int64_t start, int64_t stop) { UpdateShard(key); return AddSubrequest(impl_->Ltrim(std::move(key), start, stop)); } -RequestMget MockTransaction::Mget(std::vector keys) { +RequestMget MockPipeline::Mget(std::vector keys) { UpdateShard(keys); return AddSubrequest(impl_->Mget(std::move(keys))); } -RequestMset MockTransaction::Mset(std::vector> key_values) { +RequestMset MockPipeline::Mset(std::vector> key_values) { UpdateShard(key_values); return AddSubrequest(impl_->Mset(std::move(key_values))); } -RequestPersist MockTransaction::Persist(std::string key) { +RequestPersist MockPipeline::Persist(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Persist(std::move(key))); } -RequestPexpire MockTransaction::Pexpire(std::string key, std::chrono::milliseconds ttl) { +RequestPexpire MockPipeline::Pexpire(std::string key, std::chrono::milliseconds ttl) { UpdateShard(key); return AddSubrequest(impl_->Pexpire(std::move(key), ttl)); } -RequestPing MockTransaction::Ping(size_t shard) { +RequestPing MockPipeline::Ping(size_t shard) { UpdateShard(shard); return AddSubrequest(impl_->Ping(shard)); } -RequestPingMessage MockTransaction::PingMessage(size_t shard, std::string message) { +RequestPingMessage MockPipeline::PingMessage(size_t shard, std::string message) { UpdateShard(shard); return AddSubrequest(impl_->PingMessage(shard, std::move(message))); } -RequestRename MockTransaction::Rename(std::string key, std::string new_key) { +RequestRename MockPipeline::Rename(std::string key, std::string new_key) { UpdateShard(key); UpdateShard(new_key); return AddSubrequest(impl_->Rename(std::move(key), std::move(new_key))); } -RequestRpop MockTransaction::Rpop(std::string key) { +RequestRpop MockPipeline::Rpop(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Rpop(std::move(key))); } -RequestRpush MockTransaction::Rpush(std::string key, std::string value) { +RequestRpush MockPipeline::Rpush(std::string key, std::string value) { UpdateShard(key); return AddSubrequest(impl_->Rpush(std::move(key), std::move(value))); } -RequestRpush MockTransaction::Rpush(std::string key, std::vector values) { +RequestRpush MockPipeline::Rpush(std::string key, std::vector values) { UpdateShard(key); return AddSubrequest(impl_->Rpush(std::move(key), std::move(values))); } -RequestRpushx MockTransaction::Rpushx(std::string key, std::string element) { +RequestRpushx MockPipeline::Rpushx(std::string key, std::string element) { UpdateShard(key); return AddSubrequest(impl_->Rpushx(std::move(key), std::move(element))); } -RequestSadd MockTransaction::Sadd(std::string key, std::string member) { +RequestSadd MockPipeline::Sadd(std::string key, std::string member) { UpdateShard(key); return AddSubrequest(impl_->Sadd(std::move(key), std::move(member))); } -RequestSadd MockTransaction::Sadd(std::string key, std::vector members) { +RequestSadd MockPipeline::Sadd(std::string key, std::vector members) { UpdateShard(key); return AddSubrequest(impl_->Sadd(std::move(key), std::move(members))); } -RequestScard MockTransaction::Scard(std::string key) { +RequestScard MockPipeline::Scard(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Scard(std::move(key))); } -RequestSet MockTransaction::Set(std::string key, std::string value) { +RequestSet MockPipeline::Set(std::string key, std::string value) { UpdateShard(key); return AddSubrequest(impl_->Set(std::move(key), std::move(value))); } -RequestSet MockTransaction::Set(std::string key, std::string value, std::chrono::milliseconds ttl) { +RequestSet MockPipeline::Set(std::string key, std::string value, std::chrono::milliseconds ttl) { UpdateShard(key); return AddSubrequest(impl_->Set(std::move(key), std::move(value), ttl)); } -RequestSetIfExist MockTransaction::SetIfExist(std::string key, std::string value) { +RequestSetIfExist MockPipeline::SetIfExist(std::string key, std::string value) { UpdateShard(key); return AddSubrequest(impl_->SetIfExist(std::move(key), std::move(value))); } -RequestSetIfExist MockTransaction::SetIfExist(std::string key, std::string value, std::chrono::milliseconds ttl) { +RequestSetIfExist MockPipeline::SetIfExist(std::string key, std::string value, std::chrono::milliseconds ttl) { UpdateShard(key); return AddSubrequest(impl_->SetIfExist(std::move(key), std::move(value), ttl)); } -RequestSetIfNotExist MockTransaction::SetIfNotExist(std::string key, std::string value) { +RequestSetIfNotExist MockPipeline::SetIfNotExist(std::string key, std::string value) { UpdateShard(key); return AddSubrequest(impl_->SetIfNotExist(std::move(key), std::move(value))); } -RequestSetIfNotExist MockTransaction::SetIfNotExist(std::string key, std::string value, std::chrono::milliseconds ttl) { +RequestSetIfNotExist MockPipeline::SetIfNotExist(std::string key, std::string value, std::chrono::milliseconds ttl) { UpdateShard(key); return AddSubrequest(impl_->SetIfNotExist(std::move(key), std::move(value), ttl)); } -RequestSetIfNotExistOrGet MockTransaction::SetIfNotExistOrGet(std::string key, std::string value) { +RequestSetIfNotExistOrGet MockPipeline::SetIfNotExistOrGet(std::string key, std::string value) { UpdateShard(key); return AddSubrequest(impl_->SetIfNotExistOrGet(std::move(key), std::move(value))); } -RequestSetIfNotExistOrGet MockTransaction::SetIfNotExistOrGet( +RequestSetIfNotExistOrGet MockPipeline::SetIfNotExistOrGet( std::string key, std::string value, std::chrono::milliseconds ttl @@ -494,77 +487,77 @@ RequestSetIfNotExistOrGet MockTransaction::SetIfNotExistOrGet( return AddSubrequest(impl_->SetIfNotExistOrGet(std::move(key), std::move(value), ttl)); } -RequestSetex MockTransaction::Setex(std::string key, std::chrono::seconds seconds, std::string value) { +RequestSetex MockPipeline::Setex(std::string key, std::chrono::seconds seconds, std::string value) { UpdateShard(key); return AddSubrequest(impl_->Setex(std::move(key), seconds, std::move(value))); } -RequestSismember MockTransaction::Sismember(std::string key, std::string member) { +RequestSismember MockPipeline::Sismember(std::string key, std::string member) { UpdateShard(key); return AddSubrequest(impl_->Sismember(std::move(key), std::move(member))); } -RequestSmembers MockTransaction::Smembers(std::string key) { +RequestSmembers MockPipeline::Smembers(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Smembers(std::move(key))); } -RequestSrandmember MockTransaction::Srandmember(std::string key) { +RequestSrandmember MockPipeline::Srandmember(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Srandmember(std::move(key))); } -RequestSrandmembers MockTransaction::Srandmembers(std::string key, int64_t count) { +RequestSrandmembers MockPipeline::Srandmembers(std::string key, int64_t count) { UpdateShard(key); return AddSubrequest(impl_->Srandmembers(std::move(key), count)); } -RequestSrem MockTransaction::Srem(std::string key, std::string member) { +RequestSrem MockPipeline::Srem(std::string key, std::string member) { UpdateShard(key); return AddSubrequest(impl_->Srem(std::move(key), std::move(member))); } -RequestSrem MockTransaction::Srem(std::string key, std::vector members) { +RequestSrem MockPipeline::Srem(std::string key, std::vector members) { UpdateShard(key); return AddSubrequest(impl_->Srem(std::move(key), std::move(members))); } -RequestStrlen MockTransaction::Strlen(std::string key) { +RequestStrlen MockPipeline::Strlen(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Strlen(std::move(key))); } -RequestTime MockTransaction::Time(size_t shard) { +RequestTime MockPipeline::Time(size_t shard) { UpdateShard(shard); return AddSubrequest(impl_->Time(shard)); } -RequestTtl MockTransaction::Ttl(std::string key) { +RequestTtl MockPipeline::Ttl(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Ttl(std::move(key))); } -RequestType MockTransaction::Type(std::string key) { +RequestType MockPipeline::Type(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Type(std::move(key))); } -RequestZadd MockTransaction::Zadd(std::string key, double score, std::string member) { +RequestZadd MockPipeline::Zadd(std::string key, double score, std::string member) { UpdateShard(key); return AddSubrequest(impl_->Zadd(std::move(key), score, std::move(member))); } -RequestZadd MockTransaction::Zadd(std::string key, double score, std::string member, const ZaddOptions& options) { +RequestZadd MockPipeline::Zadd(std::string key, double score, std::string member, const ZaddOptions& options) { UpdateShard(key); return AddSubrequest(impl_->Zadd(std::move(key), score, std::move(member), options)); } -RequestZadd MockTransaction::Zadd(std::string key, std::vector> scored_members) { +RequestZadd MockPipeline::Zadd(std::string key, std::vector> scored_members) { UpdateShard(key); return AddSubrequest(impl_->Zadd(std::move(key), std::move(scored_members))); } -RequestZadd MockTransaction::Zadd( +RequestZadd MockPipeline::Zadd( std::string key, std::vector> scored_members, const ZaddOptions& options @@ -573,47 +566,47 @@ RequestZadd MockTransaction::Zadd( return AddSubrequest(impl_->Zadd(std::move(key), std::move(scored_members), options)); } -RequestZaddIncr MockTransaction::ZaddIncr(std::string key, double score, std::string member) { +RequestZaddIncr MockPipeline::ZaddIncr(std::string key, double score, std::string member) { UpdateShard(key); return AddSubrequest(impl_->ZaddIncr(std::move(key), score, std::move(member))); } -RequestZaddIncrExisting MockTransaction::ZaddIncrExisting(std::string key, double score, std::string member) { +RequestZaddIncrExisting MockPipeline::ZaddIncrExisting(std::string key, double score, std::string member) { UpdateShard(key); return AddSubrequest(impl_->ZaddIncrExisting(std::move(key), score, std::move(member))); } -RequestZcard MockTransaction::Zcard(std::string key) { +RequestZcard MockPipeline::Zcard(std::string key) { UpdateShard(key); return AddSubrequest(impl_->Zcard(std::move(key))); } -RequestZcount MockTransaction::Zcount(std::string key, double min, double max) { +RequestZcount MockPipeline::Zcount(std::string key, double min, double max) { UpdateShard(key); return AddSubrequest(impl_->Zcount(std::move(key), min, max)); } -RequestZrange MockTransaction::Zrange(std::string key, int64_t start, int64_t stop) { +RequestZrange MockPipeline::Zrange(std::string key, int64_t start, int64_t stop) { UpdateShard(key); return AddSubrequest(impl_->Zrange(std::move(key), start, stop)); } -RequestZrangeWithScores MockTransaction::ZrangeWithScores(std::string key, int64_t start, int64_t stop) { +RequestZrangeWithScores MockPipeline::ZrangeWithScores(std::string key, int64_t start, int64_t stop) { UpdateShard(key); return AddSubrequest(impl_->ZrangeWithScores(std::move(key), start, stop)); } -RequestZrangebyscore MockTransaction::Zrangebyscore(std::string key, double min, double max) { +RequestZrangebyscore MockPipeline::Zrangebyscore(std::string key, double min, double max) { UpdateShard(key); return AddSubrequest(impl_->Zrangebyscore(std::move(key), min, max)); } -RequestZrangebyscore MockTransaction::Zrangebyscore(std::string key, std::string min, std::string max) { +RequestZrangebyscore MockPipeline::Zrangebyscore(std::string key, std::string min, std::string max) { UpdateShard(key); return AddSubrequest(impl_->Zrangebyscore(std::move(key), std::move(min), std::move(max))); } -RequestZrangebyscore MockTransaction::Zrangebyscore( +RequestZrangebyscore MockPipeline::Zrangebyscore( std::string key, double min, double max, @@ -623,7 +616,7 @@ RequestZrangebyscore MockTransaction::Zrangebyscore( return AddSubrequest(impl_->Zrangebyscore(std::move(key), min, max, range_options)); } -RequestZrangebyscore MockTransaction::Zrangebyscore( +RequestZrangebyscore MockPipeline::Zrangebyscore( std::string key, std::string min, std::string max, @@ -633,12 +626,12 @@ RequestZrangebyscore MockTransaction::Zrangebyscore( return AddSubrequest(impl_->Zrangebyscore(std::move(key), std::move(min), std::move(max), range_options)); } -RequestZrangebyscoreWithScores MockTransaction::ZrangebyscoreWithScores(std::string key, double min, double max) { +RequestZrangebyscoreWithScores MockPipeline::ZrangebyscoreWithScores(std::string key, double min, double max) { UpdateShard(key); return AddSubrequest(impl_->ZrangebyscoreWithScores(std::move(key), min, max)); } -RequestZrangebyscoreWithScores MockTransaction::ZrangebyscoreWithScores( +RequestZrangebyscoreWithScores MockPipeline::ZrangebyscoreWithScores( std::string key, std::string min, std::string max @@ -647,7 +640,7 @@ RequestZrangebyscoreWithScores MockTransaction::ZrangebyscoreWithScores( return AddSubrequest(impl_->ZrangebyscoreWithScores(std::move(key), std::move(min), std::move(max))); } -RequestZrangebyscoreWithScores MockTransaction::ZrangebyscoreWithScores( +RequestZrangebyscoreWithScores MockPipeline::ZrangebyscoreWithScores( std::string key, double min, double max, @@ -657,7 +650,7 @@ RequestZrangebyscoreWithScores MockTransaction::ZrangebyscoreWithScores( return AddSubrequest(impl_->ZrangebyscoreWithScores(std::move(key), min, max, range_options)); } -RequestZrangebyscoreWithScores MockTransaction::ZrangebyscoreWithScores( +RequestZrangebyscoreWithScores MockPipeline::ZrangebyscoreWithScores( std::string key, std::string min, std::string max, @@ -667,39 +660,39 @@ RequestZrangebyscoreWithScores MockTransaction::ZrangebyscoreWithScores( return AddSubrequest(impl_->ZrangebyscoreWithScores(std::move(key), std::move(min), std::move(max), range_options)); } -RequestZrem MockTransaction::Zrem(std::string key, std::string member) { +RequestZrem MockPipeline::Zrem(std::string key, std::string member) { UpdateShard(key); return AddSubrequest(impl_->Zrem(std::move(key), std::move(member))); } -RequestZrem MockTransaction::Zrem(std::string key, std::vector members) { +RequestZrem MockPipeline::Zrem(std::string key, std::vector members) { UpdateShard(key); return AddSubrequest(impl_->Zrem(std::move(key), std::move(members))); } -RequestZremrangebyrank MockTransaction::Zremrangebyrank(std::string key, int64_t start, int64_t stop) { +RequestZremrangebyrank MockPipeline::Zremrangebyrank(std::string key, int64_t start, int64_t stop) { UpdateShard(key); return AddSubrequest(impl_->Zremrangebyrank(std::move(key), start, stop)); } -RequestZremrangebyscore MockTransaction::Zremrangebyscore(std::string key, double min, double max) { +RequestZremrangebyscore MockPipeline::Zremrangebyscore(std::string key, double min, double max) { UpdateShard(key); return AddSubrequest(impl_->Zremrangebyscore(std::move(key), min, max)); } -RequestZremrangebyscore MockTransaction::Zremrangebyscore(std::string key, std::string min, std::string max) { +RequestZremrangebyscore MockPipeline::Zremrangebyscore(std::string key, std::string min, std::string max) { UpdateShard(key); return AddSubrequest(impl_->Zremrangebyscore(std::move(key), std::move(min), std::move(max))); } -RequestZscore MockTransaction::Zscore(std::string key, std::string member) { +RequestZscore MockPipeline::Zscore(std::string key, std::string member) { UpdateShard(key); return AddSubrequest(impl_->Zscore(std::move(key), std::move(member))); } // end of redis commands -void MockTransaction::UpdateShard(const std::string& key) { +void MockPipeline::UpdateShard(const std::string& key) { try { UpdateShard(client_->ShardByKey(key)); } catch (const InvalidArgumentException& ex) { @@ -707,19 +700,19 @@ void MockTransaction::UpdateShard(const std::string& key) { } } -void MockTransaction::UpdateShard(const std::vector& keys) { +void MockPipeline::UpdateShard(const std::vector& keys) { for (const auto& key : keys) { UpdateShard(key); } } -void MockTransaction::UpdateShard(const std::vector>& key_values) { +void MockPipeline::UpdateShard(const std::vector>& key_values) { for (const auto& key_value : key_values) { UpdateShard(key_value.first); } } -void MockTransaction::UpdateShard(size_t shard) { +void MockPipeline::UpdateShard(size_t shard) { if (shard_) { if (check_shards_ == CheckShards::kSame && *shard_ != shard) { std::ostringstream os; @@ -737,15 +730,15 @@ void MockTransaction::UpdateShard(size_t shard) { } template -Request MockTransaction::AddSubrequest(Request&& subrequest) { +Request MockPipeline::AddSubrequest(Request&& subrequest) { engine::Promise promise; Request - request(std::make_unique>(promise.get_future())); + request(std::make_unique>(promise.get_future())); result_promises_.emplace_back(std::make_unique(std::move(promise), std::move(subrequest))); return request; } -RequestExec MockTransaction::CreateMockExecRequest() { +RequestExec MockPipeline::CreateMockExecRequest() { return RequestExec(std::make_unique(std::move(result_promises_))); } diff --git a/redis/testing/src/storages/redis/mock_pipeline_impl_base.cpp b/redis/testing/src/storages/redis/mock_pipeline_impl_base.cpp new file mode 100644 index 000000000000..17c81d6f00fa --- /dev/null +++ b/redis/testing/src/storages/redis/mock_pipeline_impl_base.cpp @@ -0,0 +1,508 @@ +#include + +#include + +USERVER_NAMESPACE_BEGIN + +namespace storages::redis { + +using utils::AbortWithStacktrace; + +// redis commands: + +RequestAppend MockPipelineImplBase::Append(std::string /*key*/, std::string /*value*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestBitop MockPipelineImplBase::Bitop( + BitOperation /*op*/, + std::string /*dest_key*/, + std::vector /*src_keys*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestDbsize MockPipelineImplBase::Dbsize(size_t /*shard*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestDecr MockPipelineImplBase::Decr(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestDel MockPipelineImplBase::Del(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestDel MockPipelineImplBase::Del(std::vector /*keys*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestUnlink MockPipelineImplBase::Unlink(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestUnlink MockPipelineImplBase::Unlink(std::vector /*keys*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestExists MockPipelineImplBase::Exists(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestExists MockPipelineImplBase::Exists(std::vector /*keys*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestExpire MockPipelineImplBase::Expire(std::string /*key*/, std::chrono::seconds /*ttl*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestExpire MockPipelineImplBase::Expire( + std::string /*key*/, + std::chrono::seconds /*ttl*/, + ExpireOptions /*option*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestGeoadd MockPipelineImplBase::Geoadd(std::string /*key*/, GeoaddArg /*point_member*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestGeoadd MockPipelineImplBase::Geoadd(std::string /*key*/, std::vector /*point_members*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestGeopos MockPipelineImplBase::Geopos(std::string /*key*/, std::vector /*members*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestGeoradius MockPipelineImplBase::Georadius( + std::string /*key*/, + Longitude /*lon*/, + Latitude /*lat*/, + double /*radius*/, + const GeoradiusOptions& /*georadius_options*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestGeosearch MockPipelineImplBase::Geosearch( + std::string /*key*/, + std::string /*member*/, + double /*radius*/, + const GeosearchOptions& /*geosearch_options*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestGeosearch MockPipelineImplBase::Geosearch( + std::string /*key*/, + std::string /*member*/, + BoxWidth /*width*/, + BoxHeight /*height*/, + const GeosearchOptions& /*geosearch_options*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestGeosearch MockPipelineImplBase::Geosearch( + std::string /*key*/, + Longitude /*lon*/, + Latitude /*lat*/, + double /*radius*/, + const GeosearchOptions& /*geosearch_options*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestGeosearch MockPipelineImplBase::Geosearch( + std::string /*key*/, + Longitude /*lon*/, + Latitude /*lat*/, + BoxWidth /*width*/, + BoxHeight /*height*/, + const GeosearchOptions& /*geosearch_options*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestGet MockPipelineImplBase::Get(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestGetset MockPipelineImplBase::Getset(std::string /*key*/, std::string /*value*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestHdel MockPipelineImplBase::Hdel(std::string /*key*/, std::string /*field*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestHdel MockPipelineImplBase::Hdel(std::string /*key*/, std::vector /*fields*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestHexists MockPipelineImplBase::Hexists(std::string /*key*/, std::string /*field*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestHget MockPipelineImplBase::Hget(std::string /*key*/, std::string /*field*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestHgetall MockPipelineImplBase::Hgetall(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestHincrby MockPipelineImplBase::Hincrby(std::string /*key*/, std::string /*field*/, int64_t /*increment*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestHincrbyfloat MockPipelineImplBase::Hincrbyfloat( + std::string /*key*/, + std::string /*field*/, + double /*increment*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestHkeys MockPipelineImplBase::Hkeys(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestHlen MockPipelineImplBase::Hlen(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestHmget MockPipelineImplBase::Hmget(std::string /*key*/, std::vector /*fields*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestHmset MockPipelineImplBase::Hmset( + std::string /*key*/, + std::vector> /*field_values*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestHset MockPipelineImplBase::Hset(std::string /*key*/, std::string /*field*/, std::string /*value*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestHsetnx MockPipelineImplBase::Hsetnx(std::string /*key*/, std::string /*field*/, std::string /*value*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestHvals MockPipelineImplBase::Hvals(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestIncr MockPipelineImplBase::Incr(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestKeys MockPipelineImplBase::Keys(std::string /*keys_pattern*/, size_t /*shard*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestLindex MockPipelineImplBase::Lindex(std::string /*key*/, int64_t /*index*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestLlen MockPipelineImplBase::Llen(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestLpop MockPipelineImplBase::Lpop(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestLpush MockPipelineImplBase::Lpush(std::string /*key*/, std::string /*value*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestLpush MockPipelineImplBase::Lpush(std::string /*key*/, std::vector /*values*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestLpushx MockPipelineImplBase::Lpushx(std::string /*key*/, std::string /*element*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestLrange MockPipelineImplBase::Lrange(std::string /*key*/, int64_t /*start*/, int64_t /*stop*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestLrem MockPipelineImplBase::Lrem(std::string /*key*/, int64_t /*count*/, std::string /*element*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestLtrim MockPipelineImplBase::Ltrim(std::string /*key*/, int64_t /*start*/, int64_t /*stop*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestMget MockPipelineImplBase::Mget(std::vector /*keys*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestMset MockPipelineImplBase::Mset(std::vector> /*key_values*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestPersist MockPipelineImplBase::Persist(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestPexpire MockPipelineImplBase::Pexpire(std::string /*key*/, std::chrono::milliseconds /*ttl*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestPing MockPipelineImplBase::Ping(size_t /*shard*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestPingMessage MockPipelineImplBase::PingMessage(size_t /*shard*/, std::string /*message*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestRename MockPipelineImplBase::Rename(std::string /*key*/, std::string /*new_key*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestRpop MockPipelineImplBase::Rpop(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestRpush MockPipelineImplBase::Rpush(std::string /*key*/, std::string /*value*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestRpush MockPipelineImplBase::Rpush(std::string /*key*/, std::vector /*values*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestRpushx MockPipelineImplBase::Rpushx(std::string /*key*/, std::string /*element*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSadd MockPipelineImplBase::Sadd(std::string /*key*/, std::string /*member*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSadd MockPipelineImplBase::Sadd(std::string /*key*/, std::vector /*members*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestScard MockPipelineImplBase::Scard(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestSet MockPipelineImplBase::Set(std::string /*key*/, std::string /*value*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSet MockPipelineImplBase::Set(std::string /*key*/, std::string /*value*/, std::chrono::milliseconds /*ttl*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSetIfExist MockPipelineImplBase::SetIfExist(std::string /*key*/, std::string /*value*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSetIfExist MockPipelineImplBase::SetIfExist( + std::string /*key*/, + std::string /*value*/, + std::chrono::milliseconds /*ttl*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSetIfNotExist MockPipelineImplBase::SetIfNotExist(std::string /*key*/, std::string /*value*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSetIfNotExist MockPipelineImplBase::SetIfNotExist( + std::string /*key*/, + std::string /*value*/, + std::chrono::milliseconds /*ttl*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSetIfNotExistOrGet MockPipelineImplBase::SetIfNotExistOrGet(std::string /*key*/, std::string /*value*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSetIfNotExistOrGet MockPipelineImplBase::SetIfNotExistOrGet( + std::string /*key*/, + std::string /*value*/, + std::chrono::milliseconds /*ttl*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSetex MockPipelineImplBase::Setex( + std::string /*key*/, + std::chrono::seconds /*seconds*/, + std::string /*value*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSismember MockPipelineImplBase::Sismember(std::string /*key*/, std::string /*member*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSmembers MockPipelineImplBase::Smembers(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestSrandmember MockPipelineImplBase::Srandmember(std::string /*key*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSrandmembers MockPipelineImplBase::Srandmembers(std::string /*key*/, int64_t /*count*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSrem MockPipelineImplBase::Srem(std::string /*key*/, std::string /*member*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestSrem MockPipelineImplBase::Srem(std::string /*key*/, std::vector /*members*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestStrlen MockPipelineImplBase::Strlen(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestTime MockPipelineImplBase::Time(size_t /*shard*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestTtl MockPipelineImplBase::Ttl(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestType MockPipelineImplBase::Type(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestZadd MockPipelineImplBase::Zadd(std::string /*key*/, double /*score*/, std::string /*member*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZadd MockPipelineImplBase::Zadd( + std::string /*key*/, + double /*score*/, + std::string /*member*/, + const ZaddOptions& /*options*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZadd MockPipelineImplBase::Zadd( + std::string /*key*/, + std::vector> /*scored_members*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZadd MockPipelineImplBase::Zadd( + std::string /*key*/, + std::vector> /*scored_members*/, + const ZaddOptions& /*options*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZaddIncr MockPipelineImplBase::ZaddIncr(std::string /*key*/, double /*score*/, std::string /*member*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZaddIncrExisting MockPipelineImplBase::ZaddIncrExisting( + std::string /*key*/, + double /*score*/, + std::string /*member*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZcard MockPipelineImplBase::Zcard(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } + +RequestZcount MockPipelineImplBase::Zcount(std::string /*key*/, double /*min*/, double /*max*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrange MockPipelineImplBase::Zrange(std::string /*key*/, int64_t /*start*/, int64_t /*stop*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrangeWithScores MockPipelineImplBase::ZrangeWithScores( + std::string /*key*/, + int64_t /*start*/, + int64_t /*stop*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrangebyscore MockPipelineImplBase::Zrangebyscore(std::string /*key*/, double /*min*/, double /*max*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrangebyscore MockPipelineImplBase::Zrangebyscore( + std::string /*key*/, + std::string /*min*/, + std::string /*max*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrangebyscore MockPipelineImplBase::Zrangebyscore( + std::string /*key*/, + double /*min*/, + double /*max*/, + const RangeOptions& /*range_options*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrangebyscore MockPipelineImplBase::Zrangebyscore( + std::string /*key*/, + std::string /*min*/, + std::string /*max*/, + const RangeOptions& /*range_options*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrangebyscoreWithScores MockPipelineImplBase::ZrangebyscoreWithScores( + std::string /*key*/, + double /*min*/, + double /*max*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrangebyscoreWithScores MockPipelineImplBase::ZrangebyscoreWithScores( + std::string /*key*/, + std::string /*min*/, + std::string /*max*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrangebyscoreWithScores MockPipelineImplBase::ZrangebyscoreWithScores( + std::string /*key*/, + double /*min*/, + double /*max*/, + const RangeOptions& /*range_options*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrangebyscoreWithScores MockPipelineImplBase::ZrangebyscoreWithScores( + std::string /*key*/, + std::string /*min*/, + std::string /*max*/, + const RangeOptions& /*range_options*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrem MockPipelineImplBase::Zrem(std::string /*key*/, std::string /*member*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZrem MockPipelineImplBase::Zrem(std::string /*key*/, std::vector /*members*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZremrangebyrank MockPipelineImplBase::Zremrangebyrank( + std::string /*key*/, + int64_t /*start*/, + int64_t /*stop*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZremrangebyscore MockPipelineImplBase::Zremrangebyscore(std::string /*key*/, double /*min*/, double /*max*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZremrangebyscore MockPipelineImplBase::Zremrangebyscore( + std::string /*key*/, + std::string /*min*/, + std::string /*max*/ +) { + AbortWithStacktrace("Redis method not mocked"); +} + +RequestZscore MockPipelineImplBase::Zscore(std::string /*key*/, std::string /*member*/) { + AbortWithStacktrace("Redis method not mocked"); +} + +// end of redis commands + +} // namespace storages::redis + +USERVER_NAMESPACE_END diff --git a/redis/testing/src/storages/redis/mock_transaction_impl_base.cpp b/redis/testing/src/storages/redis/mock_transaction_impl_base.cpp deleted file mode 100644 index 268037da990d..000000000000 --- a/redis/testing/src/storages/redis/mock_transaction_impl_base.cpp +++ /dev/null @@ -1,510 +0,0 @@ -#include - -#include - -USERVER_NAMESPACE_BEGIN - -namespace storages::redis { - -using utils::AbortWithStacktrace; - -// redis commands: - -RequestAppend MockTransactionImplBase::Append(std::string /*key*/, std::string /*value*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestBitop MockTransactionImplBase::Bitop( - BitOperation /*op*/, - std::string /*dest_key*/, - std::vector /*src_keys*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestDbsize MockTransactionImplBase::Dbsize(size_t /*shard*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestDecr MockTransactionImplBase::Decr(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestDel MockTransactionImplBase::Del(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestDel MockTransactionImplBase::Del(std::vector /*keys*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestUnlink MockTransactionImplBase::Unlink(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestUnlink MockTransactionImplBase::Unlink(std::vector /*keys*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestExists MockTransactionImplBase::Exists(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestExists MockTransactionImplBase::Exists(std::vector /*keys*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestExpire MockTransactionImplBase::Expire(std::string /*key*/, std::chrono::seconds /*ttl*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestExpire MockTransactionImplBase::Expire( - std::string /*key*/, - std::chrono::seconds /*ttl*/, - ExpireOptions /*option*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestGeoadd MockTransactionImplBase::Geoadd(std::string /*key*/, GeoaddArg /*point_member*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestGeoadd MockTransactionImplBase::Geoadd(std::string /*key*/, std::vector /*point_members*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestGeopos MockTransactionImplBase::Geopos(std::string /*key*/, std::vector /*members*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestGeoradius MockTransactionImplBase::Georadius( - std::string /*key*/, - Longitude /*lon*/, - Latitude /*lat*/, - double /*radius*/, - const GeoradiusOptions& /*georadius_options*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestGeosearch MockTransactionImplBase::Geosearch( - std::string /*key*/, - std::string /*member*/, - double /*radius*/, - const GeosearchOptions& /*geosearch_options*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestGeosearch MockTransactionImplBase::Geosearch( - std::string /*key*/, - std::string /*member*/, - BoxWidth /*width*/, - BoxHeight /*height*/, - const GeosearchOptions& /*geosearch_options*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestGeosearch MockTransactionImplBase::Geosearch( - std::string /*key*/, - Longitude /*lon*/, - Latitude /*lat*/, - double /*radius*/, - const GeosearchOptions& /*geosearch_options*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestGeosearch MockTransactionImplBase::Geosearch( - std::string /*key*/, - Longitude /*lon*/, - Latitude /*lat*/, - BoxWidth /*width*/, - BoxHeight /*height*/, - const GeosearchOptions& /*geosearch_options*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestGet MockTransactionImplBase::Get(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestGetset MockTransactionImplBase::Getset(std::string /*key*/, std::string /*value*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestHdel MockTransactionImplBase::Hdel(std::string /*key*/, std::string /*field*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestHdel MockTransactionImplBase::Hdel(std::string /*key*/, std::vector /*fields*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestHexists MockTransactionImplBase::Hexists(std::string /*key*/, std::string /*field*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestHget MockTransactionImplBase::Hget(std::string /*key*/, std::string /*field*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestHgetall MockTransactionImplBase::Hgetall(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestHincrby MockTransactionImplBase::Hincrby(std::string /*key*/, std::string /*field*/, int64_t /*increment*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestHincrbyfloat MockTransactionImplBase::Hincrbyfloat( - std::string /*key*/, - std::string /*field*/, - double /*increment*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestHkeys MockTransactionImplBase::Hkeys(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestHlen MockTransactionImplBase::Hlen(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestHmget MockTransactionImplBase::Hmget(std::string /*key*/, std::vector /*fields*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestHmset MockTransactionImplBase::Hmset( - std::string /*key*/, - std::vector> /*field_values*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestHset MockTransactionImplBase::Hset(std::string /*key*/, std::string /*field*/, std::string /*value*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestHsetnx MockTransactionImplBase::Hsetnx(std::string /*key*/, std::string /*field*/, std::string /*value*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestHvals MockTransactionImplBase::Hvals(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestIncr MockTransactionImplBase::Incr(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestKeys MockTransactionImplBase::Keys(std::string /*keys_pattern*/, size_t /*shard*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestLindex MockTransactionImplBase::Lindex(std::string /*key*/, int64_t /*index*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestLlen MockTransactionImplBase::Llen(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestLpop MockTransactionImplBase::Lpop(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestLpush MockTransactionImplBase::Lpush(std::string /*key*/, std::string /*value*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestLpush MockTransactionImplBase::Lpush(std::string /*key*/, std::vector /*values*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestLpushx MockTransactionImplBase::Lpushx(std::string /*key*/, std::string /*element*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestLrange MockTransactionImplBase::Lrange(std::string /*key*/, int64_t /*start*/, int64_t /*stop*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestLrem MockTransactionImplBase::Lrem(std::string /*key*/, int64_t /*count*/, std::string /*element*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestLtrim MockTransactionImplBase::Ltrim(std::string /*key*/, int64_t /*start*/, int64_t /*stop*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestMget MockTransactionImplBase::Mget(std::vector /*keys*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestMset MockTransactionImplBase::Mset(std::vector> /*key_values*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestPersist MockTransactionImplBase::Persist(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestPexpire MockTransactionImplBase::Pexpire(std::string /*key*/, std::chrono::milliseconds /*ttl*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestPing MockTransactionImplBase::Ping(size_t /*shard*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestPingMessage MockTransactionImplBase::PingMessage(size_t /*shard*/, std::string /*message*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestRename MockTransactionImplBase::Rename(std::string /*key*/, std::string /*new_key*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestRpop MockTransactionImplBase::Rpop(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestRpush MockTransactionImplBase::Rpush(std::string /*key*/, std::string /*value*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestRpush MockTransactionImplBase::Rpush(std::string /*key*/, std::vector /*values*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestRpushx MockTransactionImplBase::Rpushx(std::string /*key*/, std::string /*element*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSadd MockTransactionImplBase::Sadd(std::string /*key*/, std::string /*member*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSadd MockTransactionImplBase::Sadd(std::string /*key*/, std::vector /*members*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestScard MockTransactionImplBase::Scard(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestSet MockTransactionImplBase::Set(std::string /*key*/, std::string /*value*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSet MockTransactionImplBase::Set(std::string /*key*/, std::string /*value*/, std::chrono::milliseconds /*ttl*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSetIfExist MockTransactionImplBase::SetIfExist(std::string /*key*/, std::string /*value*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSetIfExist MockTransactionImplBase::SetIfExist( - std::string /*key*/, - std::string /*value*/, - std::chrono::milliseconds /*ttl*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSetIfNotExist MockTransactionImplBase::SetIfNotExist(std::string /*key*/, std::string /*value*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSetIfNotExist MockTransactionImplBase::SetIfNotExist( - std::string /*key*/, - std::string /*value*/, - std::chrono::milliseconds /*ttl*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSetIfNotExistOrGet MockTransactionImplBase::SetIfNotExistOrGet(std::string /*key*/, std::string /*value*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSetIfNotExistOrGet MockTransactionImplBase::SetIfNotExistOrGet( - std::string /*key*/, - std::string /*value*/, - std::chrono::milliseconds /*ttl*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSetex MockTransactionImplBase::Setex( - std::string /*key*/, - std::chrono::seconds /*seconds*/, - std::string /*value*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSismember MockTransactionImplBase::Sismember(std::string /*key*/, std::string /*member*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSmembers MockTransactionImplBase::Smembers(std::string /*key*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSrandmember MockTransactionImplBase::Srandmember(std::string /*key*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSrandmembers MockTransactionImplBase::Srandmembers(std::string /*key*/, int64_t /*count*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSrem MockTransactionImplBase::Srem(std::string /*key*/, std::string /*member*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestSrem MockTransactionImplBase::Srem(std::string /*key*/, std::vector /*members*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestStrlen MockTransactionImplBase::Strlen(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestTime MockTransactionImplBase::Time(size_t /*shard*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestTtl MockTransactionImplBase::Ttl(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestType MockTransactionImplBase::Type(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestZadd MockTransactionImplBase::Zadd(std::string /*key*/, double /*score*/, std::string /*member*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZadd MockTransactionImplBase::Zadd( - std::string /*key*/, - double /*score*/, - std::string /*member*/, - const ZaddOptions& /*options*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZadd MockTransactionImplBase::Zadd( - std::string /*key*/, - std::vector> /*scored_members*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZadd MockTransactionImplBase::Zadd( - std::string /*key*/, - std::vector> /*scored_members*/, - const ZaddOptions& /*options*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZaddIncr MockTransactionImplBase::ZaddIncr(std::string /*key*/, double /*score*/, std::string /*member*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZaddIncrExisting MockTransactionImplBase::ZaddIncrExisting( - std::string /*key*/, - double /*score*/, - std::string /*member*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZcard MockTransactionImplBase::Zcard(std::string /*key*/) { AbortWithStacktrace("Redis method not mocked"); } - -RequestZcount MockTransactionImplBase::Zcount(std::string /*key*/, double /*min*/, double /*max*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrange MockTransactionImplBase::Zrange(std::string /*key*/, int64_t /*start*/, int64_t /*stop*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrangeWithScores MockTransactionImplBase::ZrangeWithScores( - std::string /*key*/, - int64_t /*start*/, - int64_t /*stop*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrangebyscore MockTransactionImplBase::Zrangebyscore(std::string /*key*/, double /*min*/, double /*max*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrangebyscore MockTransactionImplBase::Zrangebyscore( - std::string /*key*/, - std::string /*min*/, - std::string /*max*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrangebyscore MockTransactionImplBase::Zrangebyscore( - std::string /*key*/, - double /*min*/, - double /*max*/, - const RangeOptions& /*range_options*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrangebyscore MockTransactionImplBase::Zrangebyscore( - std::string /*key*/, - std::string /*min*/, - std::string /*max*/, - const RangeOptions& /*range_options*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrangebyscoreWithScores MockTransactionImplBase::ZrangebyscoreWithScores( - std::string /*key*/, - double /*min*/, - double /*max*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrangebyscoreWithScores MockTransactionImplBase::ZrangebyscoreWithScores( - std::string /*key*/, - std::string /*min*/, - std::string /*max*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrangebyscoreWithScores MockTransactionImplBase::ZrangebyscoreWithScores( - std::string /*key*/, - double /*min*/, - double /*max*/, - const RangeOptions& /*range_options*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrangebyscoreWithScores MockTransactionImplBase::ZrangebyscoreWithScores( - std::string /*key*/, - std::string /*min*/, - std::string /*max*/, - const RangeOptions& /*range_options*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrem MockTransactionImplBase::Zrem(std::string /*key*/, std::string /*member*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZrem MockTransactionImplBase::Zrem(std::string /*key*/, std::vector /*members*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZremrangebyrank MockTransactionImplBase::Zremrangebyrank( - std::string /*key*/, - int64_t /*start*/, - int64_t /*stop*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZremrangebyscore MockTransactionImplBase::Zremrangebyscore(std::string /*key*/, double /*min*/, double /*max*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZremrangebyscore MockTransactionImplBase::Zremrangebyscore( - std::string /*key*/, - std::string /*min*/, - std::string /*max*/ -) { - AbortWithStacktrace("Redis method not mocked"); -} - -RequestZscore MockTransactionImplBase::Zscore(std::string /*key*/, std::string /*member*/) { - AbortWithStacktrace("Redis method not mocked"); -} - -// end of redis commands - -} // namespace storages::redis - -USERVER_NAMESPACE_END