Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions redis/include/userver/storages/redis/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <userver/storages/redis/bit_operation.hpp>
#include <userver/storages/redis/command_options.hpp>
#include <userver/storages/redis/request.hpp>
#include <userver/storages/redis/request_generic.hpp>

USERVER_NAMESPACE_BEGIN

Expand Down Expand Up @@ -413,7 +414,21 @@ class Transaction {

virtual RequestJsonMset JsonMset(std::vector<JsonKeyPathValue> key_path_values) = 0;

/// @brief Execute a custom Redis command.
/// @param key_index Index of the key in the args vector used to determine the shard
template <typename ReplyType>
RequestGeneric<ReplyType> GenericCommand(std::string command, std::vector<std::string> args, size_t key_index) {
return RequestGeneric<ReplyType>{GenericCommon(std::move(command), std::move(args), key_index)};
}

// end of redis commands

protected:
virtual RequestGenericCommon GenericCommon(
std::string command,
std::vector<std::string> args,
size_t key_index
) = 0;
};

using TransactionPtr = std::unique_ptr<Transaction>;
Expand Down
9 changes: 9 additions & 0 deletions redis/src/storages/redis/transaction_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,15 @@ RequestJsonMset TransactionImpl::JsonMset(std::vector<JsonKeyPathValue> key_path
return AddCmd<RequestJsonMset>("json.mset", true, std::move(args));
}

RequestGenericCommon TransactionImpl::GenericCommon(
std::string command,
std::vector<std::string> args,
size_t key_index
) {
UpdateShard(args.at(key_index));
return AddCmd<RequestGenericCommon>(std::move(command), true, std::move(args));
}

// end of redis commands

void TransactionImpl::UpdateShard(const std::string& key) {
Expand Down
2 changes: 2 additions & 0 deletions redis/src/storages/redis/transaction_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ class TransactionImpl final : public Transaction {

RequestJsonMset JsonMset(std::vector<JsonKeyPathValue> key_path_values) override;

RequestGenericCommon GenericCommon(std::string command, std::vector<std::string> args, size_t key_index) override;

// end of redis commands

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ class MockTransaction final : public Transaction {

RequestJsonMset JsonMset(std::vector<JsonKeyPathValue> key_path_values) override;

RequestGenericCommon GenericCommon(std::string command, std::vector<std::string> args, size_t key_index) override;

// end of redis commands

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ class MockTransactionImplBase {

virtual RequestJsonMset JsonMset(std::vector<JsonKeyPathValue> key_path_values);

virtual RequestGenericCommon GenericCommon(std::string command, std::vector<std::string> args, size_t key_index);

// end of redis commands
};

Expand Down
9 changes: 9 additions & 0 deletions redis/testing/src/storages/redis/mock_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,15 @@ RequestJsonMset MockTransaction::JsonMset(std::vector<JsonKeyPathValue> key_path
return AddSubrequest(impl_->JsonMset(std::move(key_path_values)));
}

RequestGenericCommon MockTransaction::GenericCommon(
std::string command,
std::vector<std::string> args,
size_t key_index
) {
UpdateShard(args.at(key_index));
return AddSubrequest(impl_->GenericCommon(std::move(command), std::move(args), key_index));
}

// end of redis commands

void MockTransaction::UpdateShard(const std::string& key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,14 @@ RequestJsonMset MockTransactionImplBase::JsonMset(std::vector<JsonKeyPathValue>
AbortWithStacktrace("Redis method not mocked");
}

RequestGenericCommon MockTransactionImplBase::GenericCommon(
std::string /*command*/,
std::vector<std::string> /*args*/,
size_t /*key_index*/
) {
AbortWithStacktrace("Redis method not mocked");
}

// end of redis commands

} // namespace storages::redis
Expand Down