Skip to content

Commit

Permalink
fix key index for eval commands within transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh-murugiah committed Oct 3, 2024
1 parent 34d78df commit 43fabda
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down

0 comments on commit 43fabda

Please sign in to comment.