Skip to content

Commit

Permalink
renaming pattern, channel, shard-channel
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 committed Jan 15, 2025
1 parent 91df97a commit f7ad3a7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/commands/client-kill.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
],
[
"8.1.0",
"`ID` option accepts multiple IDs. Added filters NAME, MINIDLE, FLAGS, PATTERN, CHANNEL and SHARDCHANNEL."
"`ID` option accepts multiple IDs. Added filters NAME, MINIDLE, FLAGS, SUBSCRIBED-PATTERN, SUBSCRIBED-CHANNEL and SUBSCRIBED-SHARD-CHANNEL"
]
],
"command_flags": [
Expand Down
2 changes: 1 addition & 1 deletion src/commands/client-list.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
],
[
"8.1.0",
"Added filters USER, ADDR, LADDR, SKIPME, MAXAGE, NAME, MINIDLE, FLAGS, PATTERN, CHANNEL and SHARDCHANNEL "
"Added filters USER, ADDR, LADDR, SKIPME, MAXAGE, NAME, MINIDLE, FLAGS, SUBSCRIBED-PATTERN, SUBSCRIBED-CHANNEL and SUBSCRIBED-SHARD-CHANNEL."
]
],
"command_flags": [
Expand Down
72 changes: 36 additions & 36 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ typedef struct {
long long min_idle;
/* Client flags for filtering. If NULL, no filtering is applied. */
char *flags;
/* Client pattern for filtering. If NULL, no filtering is applied. */
robj *pattern;
/* Client channel for filtering. If NULL, no filtering is applied. */
robj *channel;
/* Client shard channel for filtering. If NULL, no filtering is applied. */
robj *shard_channel;
/* Client subscribed pattern for filtering. If NULL, no filtering is applied. */
robj *subscribed_pattern;
/* Client subscribed channel for filtering. If NULL, no filtering is applied. */
robj *subscribed_channel;
/* Client subscribed shard channel for filtering. If NULL, no filtering is applied. */
robj *subscribed_shard_channel;
} clientFilter;

static void setProtocolError(const char *errstr, client *c);
Expand Down Expand Up @@ -3623,14 +3623,14 @@ static int parseClientFiltersOrReply(client *c, int index, clientFilter *filter)
} else if (!strcasecmp(c->argv[index]->ptr, "name") && moreargs) {
filter->name = c->argv[index + 1]->ptr;
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "pattern") && moreargs) {
filter->pattern = createObject(OBJ_STRING, sdsnew(c->argv[index + 1]->ptr));
} else if (!strcasecmp(c->argv[index]->ptr, "subscribed-pattern") && moreargs) {
filter->subscribed_pattern = createObject(OBJ_STRING, sdsnew(c->argv[index + 1]->ptr));
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "channel") && moreargs) {
filter->channel = createObject(OBJ_STRING, sdsnew(c->argv[index + 1]->ptr));
} else if (!strcasecmp(c->argv[index]->ptr, "subscribed-channel") && moreargs) {
filter->subscribed_channel = createObject(OBJ_STRING, sdsnew(c->argv[index + 1]->ptr));
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "shardchannel") && moreargs) {
filter->shard_channel = createObject(OBJ_STRING, sdsnew(c->argv[index + 1]->ptr));
} else if (!strcasecmp(c->argv[index]->ptr, "subscribed-shard-channel") && moreargs) {
filter->subscribed_shard_channel = createObject(OBJ_STRING, sdsnew(c->argv[index + 1]->ptr));
index += 2;
} else {
addReplyErrorObject(c, shared.syntaxerr);
Expand All @@ -3656,9 +3656,9 @@ static int clientMatchesFilter(client *client, clientFilter client_filter) {
return 0;
}
}
if (client_filter.pattern && !clientSubscribedToPattern(client, client_filter.pattern)) return 0;
if (client_filter.channel && !clientSubscribedToChannel(client, client_filter.channel)) return 0;
if (client_filter.shard_channel && !clientSubscribedToShardChannel(client, client_filter.shard_channel)) return 0;
if (client_filter.subscribed_pattern && !clientSubscribedToPattern(client, client_filter.subscribed_pattern)) return 0;
if (client_filter.subscribed_channel && !clientSubscribedToChannel(client, client_filter.subscribed_channel)) return 0;
if (client_filter.subscribed_shard_channel && !clientSubscribedToShardChannel(client, client_filter.subscribed_shard_channel)) return 0;

/* If all conditions are satisfied, the client matches the filter. */
return 1;
Expand Down Expand Up @@ -3806,12 +3806,12 @@ void clientHelpCommand(client *c) {
" Kill connections that include the specified flags.",
" * NAME <client-name>",
" Kill connections with the specified name.",
" * PATTERN <pattern>",
" Kill connections subscribed to a matching pattern.",
" * CHANNEL <channel>",
" Kill connections subscribed to a matching channel.",
" * SHARD-CHANNEL <shard-channel>",
" Kill connections subscribed to a matching shard channel.",
" * SUBSCRIBED-PATTERN <subscribed-pattern>",
" Kill connections subscribed to a matching subscribed pattern.",
" * SUBSCRIBED-CHANNEL <subscribed channel>",
" Kill connections subscribed to a matching subscribed channel.",
" * SUBSCRIBED-SHARD-CHANNEL <subscribed-shard-channel>",
" Kill connections subscribed to a matching subscribe shard channel.",
"LIST [options ...]",
" Return information about client connections. Options:",
" * TYPE (NORMAL|PRIMARY|REPLICA|PUBSUB)",
Expand All @@ -3834,12 +3834,12 @@ void clientHelpCommand(client *c) {
" Return clients with the specified name.",
" * MIN-IDLE <min-idle>",
" Return clients with idle time greater than or equal to <min-idle> seconds.",
" * PATTERN <pattern>",
" Return clients subscribed to a matching pattern.",
" * CHANNEL <channel>",
" Return clients subscribed to the specified channel.",
" * SHARD-CHANNEL <shard-channel>",
" Return clients subscribed to the specified shard channel.",
" * SUBSCRIBED-PATTERN <subscribed-pattern>",
" Return clients subscribed to a matching subscribed-pattern.",
" * SUBSCRIBED-CHANNEL <subscribed-channel>",
" Return clients subscribed to the specified subscribed-channel.",
" * SUBSCRIBED-SHARD-CHANNEL <shard-subscribed-channel>",
" Return clients subscribed to the specified subscribe shard channel.",
"UNPAUSE",
" Stop the current client pause, resuming traffic.",
"PAUSE <timeout> [WRITE|ALL]",
Expand Down Expand Up @@ -4007,17 +4007,17 @@ void clientKillCommand(client *c) {

static void freeClientFilter(clientFilter *filter) {
zfree(filter->ids);
if (filter->pattern) {
decrRefCount(filter->pattern);
filter->pattern = NULL;
if (filter->subscribed_pattern) {
decrRefCount(filter->subscribed_pattern);
filter->subscribed_pattern = NULL;
}
if (filter->shard_channel) {
decrRefCount(filter->shard_channel);
filter->shard_channel = NULL;
if (filter->subscribed_shard_channel) {
decrRefCount(filter->subscribed_shard_channel);
filter->subscribed_shard_channel = NULL;
}
if (filter->channel) {
decrRefCount(filter->channel);
filter->channel = NULL;
if (filter->subscribed_channel) {
decrRefCount(filter->subscribed_channel);
filter->subscribed_channel = NULL;
}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/introspection.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ start_server {tags {"introspection"}} {
$c1 psubscribe h*llo

# Fetch the client list filtered by channel
set cl [split [r client list pattern h*llo] "\r\n"]
set cl [split [r client list subscribed-pattern h*llo] "\r\n"]

# Assert the client is subscribed to the channel
foreach line $cl {
Expand All @@ -188,7 +188,7 @@ start_server {tags {"introspection"}} {
$c1 subscribe mychannel

# Fetch the client list filtered by channel
set cl [split [r client list channel mychannel] "\r\n"]
set cl [split [r client list subscribed-channel mychannel] "\r\n"]

# Assert the client is subscribed to the channel
foreach line $cl {
Expand All @@ -207,7 +207,7 @@ start_server {tags {"introspection"}} {
$c1 ssubscribe myshardchannel

# Fetch the client list filtered by channel
set cl [split [r client list shardchannel myshardchannel] "\r\n"]
set cl [split [r client list subscribed-shard-channel myshardchannel] "\r\n"]

# Assert the client is subscribed to the channel
foreach line $cl {
Expand Down Expand Up @@ -327,7 +327,7 @@ start_server {tags {"introspection"}} {
$c1 psubscribe h*llo

# Kill the client using the exact name pattern
r client kill pattern h*llo
r client kill subscribed-pattern h*llo

# Assert the client was killed
set err [catch {$c1 ping} error_message]
Expand All @@ -345,7 +345,7 @@ start_server {tags {"introspection"}} {
$c1 subscribe mychannel

# Kill the client using the channel filter
r client kill channel mychannel
r client kill subscribed-channel mychannel

# Assert the client was killed
set err [catch {$c1 ping} error_message]
Expand All @@ -363,7 +363,7 @@ start_server {tags {"introspection"}} {
$c1 ssubscribe myshardchannel

# Kill the client using the shard channel filter
r client kill shardchannel myshardchannel
r client kill subscribed-shard-channel myshardchannel

# Assert the client was killed
set err [catch {$c1 ping} error_message]
Expand Down

0 comments on commit f7ad3a7

Please sign in to comment.