Skip to content

Commit

Permalink
Fix wrong message in Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk committed Jun 13, 2024
1 parent d700038 commit e618aee
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/server/redis_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {
s = srv_->cluster->CanExecByMySelf(attributes, cmd_tokens, this);
if (!s.IsOK()) {
if (is_multi_exec) multi_error_ = true;
Reply(redis::Error({ErrorKind::None, s.Msg()}));
Reply(redis::Error(s));
continue;
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/server/redis_reply.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ void Reply(evbuffer *output, const std::string &data) { evbuffer_add(output, dat

std::string SimpleString(const std::string &data) { return "+" + data + CRLF; }

std::string Error(const Status &s) {
std::string Error(const Status &s) { return RESP_PREFIX_ERROR + StatusToRedisError(s); }

std::string StatusToRedisError(const Status &s) {
CHECK(!s.IsOK());
if (!s.Is<Status::RedisError>()) {
return "-ERR " + s.Msg() + CRLF;
return "ERR " + s.Msg() + CRLF;
}
if (auto iter = ErrorKindMap.find(s.GetErrorKind()); iter != ErrorKindMap.end()) {
return "-" + iter->second + " " + s.Msg() + CRLF;
return iter->second + " " + s.Msg() + CRLF;
}
return "-" + s.Msg() + CRLF;
return s.Msg() + CRLF;
}

std::string BulkString(const std::string &data) { return "$" + std::to_string(data.length()) + CRLF + data + CRLF; }
Expand Down
1 change: 1 addition & 0 deletions src/server/redis_reply.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void Reply(evbuffer *output, const std::string &data);
std::string SimpleString(const std::string &data);

std::string Error(const Status &s);
std::string StatusToRedisError(const Status &s);

template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>
std::string Integer(T data) {
Expand Down
2 changes: 1 addition & 1 deletion src/storage/scripting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ int RedisGenericCommand(lua_State *lua, int raise_error) {
if (config->cluster_enabled) {
auto s = srv->cluster->CanExecByMySelf(attributes, args, conn);
if (!s.IsOK()) {
PushError(lua, s.Msg().c_str());
PushError(lua, redis::StatusToRedisError(s).c_str());
return raise_error ? RaiseError(lua) : 1;
}
}
Expand Down

0 comments on commit e618aee

Please sign in to comment.