Skip to content

Commit

Permalink
show capa in CLIENT LIST (#1698)
Browse files Browse the repository at this point in the history
Signed-off-by: zhaozhao.zz <zhaozhao.zz@alibaba-inc.com>
  • Loading branch information
soloestoy authored Feb 10, 2025
1 parent 0e66aaa commit 96857bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -3346,7 +3346,7 @@ int isClientConnIpV6(client *c) {
* readable format, into the sds string 's'. */
sds catClientInfoString(sds s, client *client, int hide_user_data) {
if (!server.crashed) waitForClientIO(client);
char flags[17], events[3], conninfo[CONN_INFO_LEN], *p;
char flags[17], events[3], capa[9], conninfo[CONN_INFO_LEN], *p;

p = flags;
if (client->flag.replica) {
Expand Down Expand Up @@ -3382,6 +3382,10 @@ sds catClientInfoString(sds s, client *client, int hide_user_data) {
}
*p = '\0';

p = capa;
if (client->capa & CLIENT_CAPA_REDIRECT) *p++ = 'r';
*p = '\0';

/* Compute the total memory consumed by this client. */
size_t obufmem, total_mem = getClientMemoryUsage(client, &obufmem);

Expand All @@ -3402,6 +3406,7 @@ sds catClientInfoString(sds s, client *client, int hide_user_data) {
" age=%I", (long long)(commandTimeSnapshot() / 1000 - client->ctime),
" idle=%I", (long long)(server.unixtime - client->last_interaction),
" flags=%s", flags,
" capa=%s", capa,
" db=%i", client->db->id,
" sub=%i", client->pubsub_data ? (int)dictSize(client->pubsub_data->pubsub_channels) : 0,
" psub=%i", client->pubsub_data ? (int)dictSize(client->pubsub_data->pubsub_patterns) : 0,
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/replica-redirect.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ start_server {tags {needs:repl external:skip}} {
assert_error "REDIRECT $primary_host:$primary_port" {r get foo}
}

test {CLIENT INFO} {
r client info
} {id=* addr=*:* laddr=*:* fd=* name=* age=* idle=* flags=N capa=r db=* sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=* argv-mem=* multi-mem=0 rbs=* rbp=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client|info user=* redir=-1 resp=* lib-name=* lib-ver=* tot-net-in=* tot-net-out=* tot-cmds=*}

test {non-data access commands are not redirected} {
r ping
} {PONG}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/introspection.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ start_server {tags {"introspection"}} {

test {CLIENT LIST} {
r client list
} {id=* addr=*:* laddr=*:* fd=* name=* age=* idle=* flags=N db=* sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=* argv-mem=* multi-mem=0 rbs=* rbp=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client|list user=* redir=-1 resp=* lib-name=* lib-ver=* tot-net-in=* tot-net-out=* tot-cmds=*}
} {id=* addr=*:* laddr=*:* fd=* name=* age=* idle=* flags=N capa= db=* sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=* argv-mem=* multi-mem=0 rbs=* rbp=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client|list user=* redir=-1 resp=* lib-name=* lib-ver=* tot-net-in=* tot-net-out=* tot-cmds=*}

test {CLIENT LIST with IDs} {
set myid [r client id]
Expand All @@ -17,7 +17,7 @@ start_server {tags {"introspection"}} {

test {CLIENT INFO} {
r client info
} {id=* addr=*:* laddr=*:* fd=* name=* age=* idle=* flags=N db=* sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=* argv-mem=* multi-mem=0 rbs=* rbp=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client|info user=* redir=-1 resp=* lib-name=* lib-ver=* tot-net-in=* tot-net-out=* tot-cmds=*}
} {id=* addr=*:* laddr=*:* fd=* name=* age=* idle=* flags=N capa= db=* sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=* argv-mem=* multi-mem=0 rbs=* rbp=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client|info user=* redir=-1 resp=* lib-name=* lib-ver=* tot-net-in=* tot-net-out=* tot-cmds=*}

test {CLIENT LIST with ADDR filter} {
set client_info [r client info]
Expand Down

0 comments on commit 96857bf

Please sign in to comment.