@@ -131,10 +131,24 @@ redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args)
131
131
return NULL ;
132
132
}
133
133
// Branch based on the directive
134
- if (!strcasecmp (Z_STRVAL (z_args [0 ]), "flush" ) || ! strcasecmp ( Z_STRVAL ( z_args [ 0 ]), " kill" )) {
135
- // Simple SCRIPT FLUSH, or SCRIPT_KILL command
134
+ if (!strcasecmp (Z_STRVAL (z_args [0 ]), "kill" )) {
135
+ // Simple SCRIPT_KILL command
136
136
REDIS_CMD_INIT_SSTR_STATIC (cmd , argc , "SCRIPT" );
137
- redis_cmd_append_sstr (cmd , Z_STRVAL (z_args [0 ]), Z_STRLEN (z_args [0 ]));
137
+ redis_cmd_append_sstr (cmd , "KILL" , sizeof ("KILL" ) - 1 );
138
+ } else if (!strcasecmp (Z_STRVAL (z_args [0 ]), "flush" )) {
139
+ // Simple SCRIPT FLUSH [ASYNC | SYNC]
140
+ if (argc > 1 && (
141
+ Z_TYPE (z_args [1 ]) != IS_STRING ||
142
+ strcasecmp (Z_STRVAL (z_args [1 ]), "sync" ) ||
143
+ strcasecmp (Z_STRVAL (z_args [1 ]), "async" )
144
+ )) {
145
+ return NULL ;
146
+ }
147
+ REDIS_CMD_INIT_SSTR_STATIC (cmd , argc , "SCRIPT" );
148
+ redis_cmd_append_sstr (cmd , "FLUSH" , sizeof ("FLUSH" ) - 1 );
149
+ if (argc > 1 ) {
150
+ redis_cmd_append_sstr (cmd , Z_STRVAL (z_args [1 ]), Z_STRLEN (z_args [1 ]));
151
+ }
138
152
} else if (!strcasecmp (Z_STRVAL (z_args [0 ]), "load" )) {
139
153
// Make sure we have a second argument, and it's not empty. If it is
140
154
// empty, we can just return an empty array (which is what Redis does)
@@ -436,16 +450,18 @@ int redis_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
436
450
int redis_flush_cmd (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock ,
437
451
char * kw , char * * cmd , int * cmd_len , short * slot , void * * ctx )
438
452
{
439
- zend_bool async = 0 ;
453
+ zend_bool sync = -1 ;
440
454
441
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "|b" , & async ) == FAILURE ) {
455
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "|b" , & sync ) == FAILURE ) {
442
456
return FAILURE ;
443
457
}
444
458
445
- if (async ) {
446
- * cmd_len = REDIS_CMD_SPPRINTF (cmd , kw , "s" , "ASYNC" , sizeof ("ASYNC" ) - 1 );
447
- } else {
459
+ if (sync < 0 ) {
448
460
* cmd_len = REDIS_CMD_SPPRINTF (cmd , kw , "" );
461
+ } else if (sync > 0 ) {
462
+ * cmd_len = REDIS_CMD_SPPRINTF (cmd , kw , "s" , "SYNC" , sizeof ("SYNC" ) - 1 );
463
+ } else {
464
+ * cmd_len = REDIS_CMD_SPPRINTF (cmd , kw , "s" , "ASYNC" , sizeof ("ASYNC" ) - 1 );
449
465
}
450
466
451
467
return SUCCESS ;
0 commit comments