From 43fabdaaec16a3c089aed4efb7ae630dfe6504db Mon Sep 17 00:00:00 2001 From: dinesh-murugiah Date: Thu, 3 Oct 2024 17:34:36 +0530 Subject: [PATCH] fix key index for eval commands within transaction --- .../network/redis_proxy/command_splitter_impl.cc | 10 ++++++++-- .../network/redis_proxy/command_splitter_impl.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/extensions/filters/network/redis_proxy/command_splitter_impl.cc b/source/extensions/filters/network/redis_proxy/command_splitter_impl.cc index 5925121c1632..e73f2788696a 100644 --- a/source/extensions/filters/network/redis_proxy/command_splitter_impl.cc +++ b/source/extensions/filters/network/redis_proxy/command_splitter_impl.cc @@ -1636,7 +1636,7 @@ void SplitKeysSumResultRequest::onChildResponse(Common::Redis::RespValuePtr&& va } } -int32_t TransactionRequest::getShardingKeyIndex(const std::string command_name, const Common::Redis::RespValue& request) { +int32_t TransactionRequest::getShardingKeyIndex(const std::string& command_name, const Common::Redis::RespValue& request) { if (command_name == "xread" || command_name == "xreadgroup") { int32_t count = request.asArray().size(); for (int32_t index = 0; index < count; ++index) { @@ -1655,7 +1655,13 @@ int32_t TransactionRequest::getShardingKeyIndex(const std::string command_name, } else { return -1; // Not enough elements } - } else { + } else if(Common::Redis::SupportedCommands::evalCommands().contains(command_name)) { + if (!(request.asArray().size() < 4)) { + return 3; // Return index 3 for eval commands + } else { + return -1; // Not enough arguments to process in transaction + } + }else { return 1; // Default case for other commands } } diff --git a/source/extensions/filters/network/redis_proxy/command_splitter_impl.h b/source/extensions/filters/network/redis_proxy/command_splitter_impl.h index 6fe814989c69..5d8bac3efb11 100644 --- a/source/extensions/filters/network/redis_proxy/command_splitter_impl.h +++ b/source/extensions/filters/network/redis_proxy/command_splitter_impl.h @@ -415,7 +415,7 @@ class TransactionRequest : public SingleServerRequest { TransactionRequest(SplitCallbacks& callbacks, CommandStats& command_stats, TimeSource& time_source, bool delay_command_latency) : SingleServerRequest(callbacks, command_stats, time_source, delay_command_latency) {} - static int32_t getShardingKeyIndex(const std::string command_name,const Common::Redis::RespValue& request); + static int32_t getShardingKeyIndex(const std::string& command_name,const Common::Redis::RespValue& request); }; /**