Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85ee61d

Browse files
Add prefix support to SUBSCRIBE/PSUBSCRIBE
Now the Redis::OPT_PREFIX will apply to subscribe/psubscribe channels and will be applied before searching for messages.
1 parent 242a16d commit 85ee61d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

redis.c

+17-3
Original file line numberDiff line numberDiff line change
@@ -5322,8 +5322,8 @@ PHPAPI void generic_subscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, char *sub_cmd)
53225322
HashTable *arr_hash;
53235323
HashPosition pointer;
53245324
RedisSock *redis_sock;
5325-
char *cmd = "", *old_cmd = NULL;
5326-
int cmd_len, array_count;
5325+
char *cmd = "", *old_cmd = NULL, *key;
5326+
int cmd_len, array_count, key_len, key_free;
53275327
zval *z_tab, **tmp;
53285328
char *type_response;
53295329

@@ -5358,10 +5358,24 @@ PHPAPI void generic_subscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, char *sub_cmd)
53585358
if(*cmd) {
53595359
old_cmd = cmd;
53605360
}
5361-
cmd_len = spprintf(&cmd, 0, "%s %s", cmd, Z_STRVAL_PP(data));
5361+
5362+
// Grab our key and len
5363+
key = Z_STRVAL_PP(data);
5364+
key_len = Z_STRLEN_PP(data);
5365+
5366+
// Prefix our key if neccisary
5367+
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
5368+
5369+
cmd_len = spprintf(&cmd, 0, "%s %s", cmd, key);
5370+
53625371
if(old_cmd) {
53635372
efree(old_cmd);
53645373
}
5374+
5375+
// Free our key if it was prefixed
5376+
if(key_free) {
5377+
efree(key);
5378+
}
53655379
}
53665380
}
53675381

0 commit comments

Comments
 (0)