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

Skip to content

Commit 7c55142

Browse files
committed
Refactor redis_script_cmd
- Update redis_script_cmd to use redis_build_script_cmd. - Fix condition for parsing sync/async arguments of flush sub-command.
1 parent 5730497 commit 7c55142

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

redis_commands.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,17 @@ redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args)
168168
return NULL;
169169
}
170170
// Branch based on the directive
171-
if (!strcasecmp(Z_STRVAL(z_args[0]), "kill")) {
171+
if (zend_string_equals_literal_ci(Z_STR(z_args[0]), "kill")) {
172172
// Simple SCRIPT_KILL command
173173
REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT");
174174
redis_cmd_append_sstr(cmd, ZEND_STRL("KILL"));
175-
} else if (!strcasecmp(Z_STRVAL(z_args[0]), "flush")) {
175+
} else if (zend_string_equals_literal_ci(Z_STR(z_args[0]), "flush")) {
176176
// Simple SCRIPT FLUSH [ASYNC | SYNC]
177177
if (argc > 1 && (
178-
Z_TYPE(z_args[1]) != IS_STRING ||
179-
strcasecmp(Z_STRVAL(z_args[1]), "sync") ||
180-
strcasecmp(Z_STRVAL(z_args[1]), "async")
178+
Z_TYPE(z_args[1]) != IS_STRING || (
179+
!zend_string_equals_literal_ci(Z_STR(z_args[1]), "sync") &&
180+
!zend_string_equals_literal_ci(Z_STR(z_args[1]), "async")
181+
)
181182
)) {
182183
return NULL;
183184
}
@@ -186,7 +187,7 @@ redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args)
186187
if (argc > 1) {
187188
redis_cmd_append_sstr(cmd, Z_STRVAL(z_args[1]), Z_STRLEN(z_args[1]));
188189
}
189-
} else if (!strcasecmp(Z_STRVAL(z_args[0]), "load")) {
190+
} else if (zend_string_equals_literal_ci(Z_STR(z_args[0]), "load")) {
190191
// Make sure we have a second argument, and it's not empty. If it is
191192
// empty, we can just return an empty array (which is what Redis does)
192193
if (argc < 2 || Z_TYPE(z_args[1]) != IS_STRING || Z_STRLEN(z_args[1]) < 1) {
@@ -196,7 +197,7 @@ redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args)
196197
REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT");
197198
redis_cmd_append_sstr(cmd, ZEND_STRL("LOAD"));
198199
redis_cmd_append_sstr(cmd, Z_STRVAL(z_args[1]), Z_STRLEN(z_args[1]));
199-
} else if (!strcasecmp(Z_STRVAL(z_args[0]), "exists")) {
200+
} else if (zend_string_equals_literal_ci(Z_STR(z_args[0]), "exists")) {
200201
// Make sure we have a second argument
201202
if (argc < 2) {
202203
return NULL;
@@ -2106,8 +2107,22 @@ int redis_info_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
21062107
int redis_script_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
21072108
char **cmd, int *cmd_len, short *slot, void **ctx)
21082109
{
2109-
return gen_vararg_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, 1,
2110-
"SCRIPT", cmd, cmd_len, slot, ctx);
2110+
int argc = 0;
2111+
smart_string cmdstr = {0};
2112+
zval *argv = NULL;
2113+
2114+
ZEND_PARSE_PARAMETERS_START(1, -1)
2115+
Z_PARAM_VARIADIC('*', argv, argc)
2116+
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
2117+
2118+
if (redis_build_script_cmd(&cmdstr, argc, argv) == NULL) {
2119+
return FAILURE;
2120+
}
2121+
2122+
*cmd = cmdstr.c;
2123+
*cmd_len = cmdstr.len;
2124+
2125+
return SUCCESS;
21112126
}
21122127

21132128
/* Generic handling of every blocking pop command (BLPOP, BZPOP[MIN/MAX], etc */

0 commit comments

Comments
 (0)