Skip to content

Commit 4c237c7

Browse files
committed
Added prefix support for varg commands (DEL...)
1 parent 2e7e610 commit 4c237c7

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

redis.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,12 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword
19151915
RETURN_FALSE;
19161916
}
19171917

1918+
/* get redis socket */
1919+
if (redis_sock_get(getThis(), out_sock TSRMLS_CC) < 0) {
1920+
RETURN_FALSE;
1921+
}
1922+
redis_sock = *out_sock;
1923+
19181924
z_args = emalloc(argc * sizeof(zval*));
19191925
if(zend_get_parameters_array(ht, argc, z_args) == FAILURE) {
19201926
efree(z_args);
@@ -1979,6 +1985,9 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword
19791985
/* get current value */
19801986
keys[j] = Z_STRVAL_PP(z_value_pp);
19811987
keys_len[j] = Z_STRLEN_PP(z_value_pp);
1988+
1989+
redis_key_prefix(redis_sock, &keys[j], &keys_len[j] TSRMLS_CC); /* add optional prefix */
1990+
19821991
cmd_len += 1 + integer_length(keys_len[j]) + 2 + keys_len[j] + 2; /* $ + size + NL + string + NL */
19831992
j++;
19841993
real_argc++;
@@ -2004,6 +2013,9 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword
20042013
if(Z_TYPE_P(z_args[i]) == IS_STRING) {
20052014
keys[j] = Z_STRVAL_P(z_args[i]);
20062015
keys_len[j] = Z_STRLEN_P(z_args[i]);
2016+
2017+
redis_key_prefix(redis_sock, &keys[j], &keys_len[j] TSRMLS_CC); /* add optional prefix */
2018+
20072019
cmd_len += 1 + integer_length(keys_len[j]) + 2 + keys_len[j] + 2; /* $ + size + NL + string + NL */
20082020
j++;
20092021
real_argc++;
@@ -2017,15 +2029,6 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword
20172029
}
20182030
}
20192031

2020-
/* get redis socket */
2021-
if (redis_sock_get(getThis(), out_sock TSRMLS_CC) < 0) {
2022-
efree(keys);
2023-
efree(keys_len);
2024-
if(z_args) efree(z_args);
2025-
RETURN_FALSE;
2026-
}
2027-
redis_sock = *out_sock;
2028-
20292032
cmd_len += 1 + integer_length(real_argc+1) + 2; // *count NL
20302033
cmd = emalloc(cmd_len+1);
20312034

@@ -2045,6 +2048,13 @@ PHPAPI int generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword
20452048
pos += 2;
20462049
}
20472050

2051+
/* cleanup prefixed keys. */
2052+
if(redis_sock->prefix && redis_sock->prefix_len) {
2053+
for(i = 0; i < real_argc + (has_timeout?-1:0); ++i) {
2054+
efree(keys[i]);
2055+
}
2056+
}
2057+
20482058
efree(keys);
20492059
efree(keys_len);
20502060

0 commit comments

Comments
 (0)