Skip to content

Commit

Permalink
RESP3 support for monitor command
Browse files Browse the repository at this point in the history
  • Loading branch information
KowalczykBartek committed Dec 11, 2024
1 parent 3eb8314 commit 30c1c7e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,14 @@ void replicationFeedMonitors(client *c, list *monitors, int dictid, robj **argv,
listRewind(monitors, &li);
while ((ln = listNext(&li))) {
client *monitor = ln->value;
addReply(monitor, cmdobj);
if(monitor->resp > 2) {
monitor->flag.pushing = 1;
addReplyPushLen(monitor,2);
addReply(monitor,shared.monitorbulk);
addReply(monitor,cmdobj);
} else {
addReply(monitor,cmdobj);
}
updateClientMemUsageAndBucket(monitor);
}
decrRefCount(cmdobj);
Expand Down
1 change: 1 addition & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,7 @@ void createSharedObjects(void) {
shared.ssubscribebulk = createStringObject("$10\r\nssubscribe\r\n", 17);
shared.sunsubscribebulk = createStringObject("$12\r\nsunsubscribe\r\n", 19);
shared.smessagebulk = createStringObject("$8\r\nsmessage\r\n", 14);
shared.monitorbulk = createStringObject("$7\r\nmonitor\r\n", 13);
shared.psubscribebulk = createStringObject("$10\r\npsubscribe\r\n", 17);
shared.punsubscribebulk = createStringObject("$12\r\npunsubscribe\r\n", 19);

Expand Down
2 changes: 1 addition & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ struct sharedObjectsStruct {
*xgroup, *xclaim, *script, *replconf, *eval, *persist, *set, *pexpireat, *pexpire, *time, *pxat, *absttl,
*retrycount, *force, *justid, *entriesread, *lastid, *ping, *setid, *keepttl, *load, *createconsumer, *getack,
*special_asterick, *special_equals, *default_username, *redacted, *ssubscribebulk, *sunsubscribebulk,
*smessagebulk, *select[PROTO_SHARED_SELECT_CMDS], *integers[OBJ_SHARED_INTEGERS],
*smessagebulk, *monitorbulk, *select[PROTO_SHARED_SELECT_CMDS], *integers[OBJ_SHARED_INTEGERS],
*mbulkhdr[OBJ_SHARED_BULKHDR_LEN], /* "*<value>\r\n" */
*bulkhdr[OBJ_SHARED_BULKHDR_LEN], /* "$<value>\r\n" */
*maphdr[OBJ_SHARED_BULKHDR_LEN], /* "%<value>\r\n" */
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/introspection.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,20 @@ start_server {tags {"introspection"}} {
set _ $res
} {*"set" "foo"*"get" "foo"*}

test {MONITOR should support RESP3 protocol} {
set rd [valkey_deferring_client]
$rd HELLO 3
$rd read ; # Consume the HELLO reply

$rd monitor
$rd read ; # Consume the MONITOR reply

r set foo bar

assert_match {monitor*"set"*"foo"*"bar"*} [$rd read]
$rd close
}

test {MONITOR can log commands issued by the scripting engine} {
set rd [valkey_deferring_client]
$rd monitor
Expand Down

0 comments on commit 30c1c7e

Please sign in to comment.