@@ -131,10 +131,24 @@ redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args)
131131 return NULL ;
132132 }
133133 // 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
136136 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+ }
138152 } else if (!strcasecmp (Z_STRVAL (z_args [0 ]), "load" )) {
139153 // Make sure we have a second argument, and it's not empty. If it is
140154 // 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,
436450int redis_flush_cmd (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock ,
437451 char * kw , char * * cmd , int * cmd_len , short * slot , void * * ctx )
438452{
439- zend_bool async = 0 ;
453+ zend_bool sync = -1 ;
440454
441- if (zend_parse_parameters (ZEND_NUM_ARGS (), "|b" , & async ) == FAILURE ) {
455+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "|b" , & sync ) == FAILURE ) {
442456 return FAILURE ;
443457 }
444458
445- if (async ) {
446- * cmd_len = REDIS_CMD_SPPRINTF (cmd , kw , "s" , "ASYNC" , sizeof ("ASYNC" ) - 1 );
447- } else {
459+ if (sync < 0 ) {
448460 * 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 );
449465 }
450466
451467 return SUCCESS ;
0 commit comments