spicy-redis: Separate error replies from success

This commit is contained in:
Evan Typanski 2025-05-23 15:02:53 -04:00
parent d5b121db14
commit b4429a995a
21 changed files with 130 additions and 73 deletions

View file

@ -22,8 +22,10 @@ export {
id: conn_id &log;
## The Redis command.
cmd: Command &log;
## If the command was successful. Only set if the server responded.
success: bool &log &optional;
## The reply for the command.
reply: ServerData &log &optional;
reply: ReplyData &log &optional;
};
## A default logging policy hook for the stream.
@ -198,16 +200,9 @@ function reply_num(c: connection): count
return resp_num;
}
event Redis::reply(c: connection, data: Redis::ServerData)
# Logs up to and including the last seen command from the last reply
function log_from(c: connection, previous_reply_num: count)
{
if ( ! c?$redis_state )
make_new_state(c);
local previous_reply_num = c$redis_state$current_reply;
c$redis_state$current_reply = reply_num(c);
set_state(c, F);
c$redis$reply = data;
# Log each of the pending replies to this point - we will not go
# back.
while ( previous_reply_num < c$redis_state$current_reply )
@ -234,6 +229,34 @@ event Redis::reply(c: connection, data: Redis::ServerData)
}
}
event Redis::reply(c: connection, data: ReplyData)
{
if ( ! c?$redis_state )
make_new_state(c);
local previous_reply_num = c$redis_state$current_reply;
c$redis_state$current_reply = reply_num(c);
set_state(c, F);
c$redis$reply = data;
c$redis$success = T;
log_from(c, previous_reply_num);
}
event Redis::error(c: connection, data: ReplyData)
{
if ( ! c?$redis_state )
make_new_state(c);
local previous_reply_num = c$redis_state$current_reply;
c$redis_state$current_reply = reply_num(c);
set_state(c, F);
c$redis$reply = data;
c$redis$success = F;
log_from(c, previous_reply_num);
}
hook finalize_redis(c: connection)
{
if ( c$redis_state$violation )

View file

@ -52,12 +52,9 @@ export {
known: KnownCommand &optional;
};
## Generic server data returned from the server.
type ServerData: record {
## Did the server reply without erroring?
success: bool &log;
## The string response, if it was a simple string or error
data: string &log &optional;
## A generic Redis reply from the client.
type ReplyData: record {
value: string &log &optional;
};
}
@ -89,9 +86,18 @@ global auth_command: event(c: connection, command: AuthCommand);
## cmd: The command sent to the server.
global command: event(c: connection, cmd: Command);
## Generated for every response sent by the Redis server to the client.
## Generated for every successful response sent by the Redis server to the
## client.
##
## c: The connection.
##
## data: The server data sent to the client.
global reply: event(c: connection, data: ServerData);
global reply: event(c: connection, data: ReplyData);
## Generated for every error response sent by the Redis server to the
## client.
##
## c: The connection.
##
## data: The server data sent to the client.
global error: event(c: connection, data: ReplyData);