@@ -1030,9 +1030,11 @@ clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, in
10301030 mc .cmd = cmd ;
10311031 }
10321032
1033- int is_pubsubshard = cmd -> proc == ssubscribeCommand ||
1034- cmd -> proc == sunsubscribeCommand ||
1035- cmd -> proc == spublishCommand ;
1033+ uint64_t cmd_flags = getCommandFlags (c );
1034+
1035+ /* Only valid for sharded pubsub as regular pubsub can operate on any node and bypasses this layer. */
1036+ int pubsubshard_included = (cmd_flags & CMD_PUBSUB ) ||
1037+ (c -> cmd -> proc == execCommand && (c -> mstate .cmd_flags & CMD_PUBSUB ));
10361038
10371039 /* Check that all the keys are in the same hash slot, and obtain this
10381040 * slot and the node associated. */
@@ -1109,7 +1111,7 @@ clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, in
11091111 * node until the migration completes with CLUSTER SETSLOT <slot>
11101112 * NODE <node-id>. */
11111113 int flags = LOOKUP_NOTOUCH | LOOKUP_NOSTATS | LOOKUP_NONOTIFY | LOOKUP_NOEXPIRE ;
1112- if ((migrating_slot || importing_slot ) && !is_pubsubshard )
1114+ if ((migrating_slot || importing_slot ) && !pubsubshard_included )
11131115 {
11141116 if (lookupKeyReadWithFlags (& server .db [0 ], thiskey , flags ) == NULL ) missing_keys ++ ;
11151117 else existing_keys ++ ;
@@ -1122,11 +1124,10 @@ clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, in
11221124 * without redirections or errors in all the cases. */
11231125 if (n == NULL ) return myself ;
11241126
1125- uint64_t cmd_flags = getCommandFlags (c );
11261127 /* Cluster is globally down but we got keys? We only serve the request
11271128 * if it is a read command and when allow_reads_when_down is enabled. */
11281129 if (!isClusterHealthy ()) {
1129- if (is_pubsubshard ) {
1130+ if (pubsubshard_included ) {
11301131 if (!server .cluster_allow_pubsubshard_when_down ) {
11311132 if (error_code ) * error_code = CLUSTER_REDIR_DOWN_STATE ;
11321133 return NULL ;
@@ -1189,7 +1190,7 @@ clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, in
11891190 * is serving, we can reply without redirection. */
11901191 int is_write_command = (cmd_flags & CMD_WRITE ) ||
11911192 (c -> cmd -> proc == execCommand && (c -> mstate .cmd_flags & CMD_WRITE ));
1192- if (((c -> flags & CLIENT_READONLY ) || is_pubsubshard ) &&
1193+ if (((c -> flags & CLIENT_READONLY ) || pubsubshard_included ) &&
11931194 !is_write_command &&
11941195 clusterNodeIsSlave (myself ) &&
11951196 clusterNodeGetSlaveof (myself ) == n )
0 commit comments