@@ -84,6 +84,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_info, 0, 0, 1)
8484 ZEND_ARG_INFO (0 , option )
8585ZEND_END_ARG_INFO ()
8686
87+ ZEND_BEGIN_ARG_INFO_EX (arginfo_flush , 0 , 0 , 1 )
88+ ZEND_ARG_INFO (0 , key_or_address )
89+ ZEND_ARG_INFO (0 , async )
90+ ZEND_END_ARG_INFO ()
91+
8792/* Argument info for HSCAN, SSCAN, HSCAN */
8893ZEND_BEGIN_ARG_INFO_EX (arginfo_kscan_cl , 0 , 0 , 2 )
8994 ZEND_ARG_INFO (0 , str_key )
@@ -136,8 +141,8 @@ zend_function_entry redis_cluster_functions[] = {
136141 PHP_ME (RedisCluster , exists , arginfo_key , ZEND_ACC_PUBLIC )
137142 PHP_ME (RedisCluster , expire , arginfo_expire , ZEND_ACC_PUBLIC )
138143 PHP_ME (RedisCluster , expireat , arginfo_key_timestamp , ZEND_ACC_PUBLIC )
139- PHP_ME (RedisCluster , flushall , arginfo_key_or_address , ZEND_ACC_PUBLIC )
140- PHP_ME (RedisCluster , flushdb , arginfo_key_or_address , ZEND_ACC_PUBLIC )
144+ PHP_ME (RedisCluster , flushall , arginfo_flush , ZEND_ACC_PUBLIC )
145+ PHP_ME (RedisCluster , flushdb , arginfo_flush , ZEND_ACC_PUBLIC )
141146 PHP_ME (RedisCluster , geoadd , arginfo_geoadd , ZEND_ACC_PUBLIC )
142147 PHP_ME (RedisCluster , geodist , arginfo_geodist , ZEND_ACC_PUBLIC )
143148 PHP_ME (RedisCluster , geohash , arginfo_key_members , ZEND_ACC_PUBLIC )
@@ -2334,6 +2339,50 @@ cluster_empty_node_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw,
23342339 efree (cmd );
23352340}
23362341
2342+ static void
2343+ cluster_flush_cmd (INTERNAL_FUNCTION_PARAMETERS , char * kw , REDIS_REPLY_TYPE reply_type , cluster_cb cb )
2344+ {
2345+ redisCluster * c = GET_CONTEXT ();
2346+ char * cmd ;
2347+ int cmd_len ;
2348+ zval * z_arg ;
2349+ zend_bool async = 0 ;
2350+ short slot ;
2351+
2352+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "z|b" , & z_arg , & async ) == FAILURE ) {
2353+ RETURN_FALSE ;
2354+ }
2355+
2356+ // One argument means find the node (treated like a key), and two means
2357+ // send the command to a specific host and port
2358+ slot = cluster_cmd_get_slot (c , z_arg TSRMLS_CC );
2359+ if (slot < 0 ) {
2360+ RETURN_FALSE ;
2361+ }
2362+
2363+ // Construct our command
2364+ if (async ) {
2365+ cmd_len = redis_spprintf (NULL , NULL TSRMLS_CC , & cmd , kw , "s" , "ASYNC" , sizeof ("ASYNC" ) - 1 );
2366+ } else {
2367+ cmd_len = redis_spprintf (NULL , NULL TSRMLS_CC , & cmd , kw , "" );
2368+ }
2369+
2370+
2371+ // Kick off our command
2372+ if (cluster_send_slot (c , slot , cmd , cmd_len , reply_type TSRMLS_CC ) < 0 ) {
2373+ zend_throw_exception (redis_cluster_exception_ce ,
2374+ "Unable to send command at a specific node" , 0 TSRMLS_CC );
2375+ efree (cmd );
2376+ RETURN_FALSE ;
2377+ }
2378+
2379+ // Our response callback
2380+ cb (INTERNAL_FUNCTION_PARAM_PASSTHRU , c , NULL );
2381+
2382+ // Free our command
2383+ efree (cmd );
2384+ }
2385+
23372386/* Generic routine for handling various commands which need to be directed at
23382387 * a node, but have complex syntax. We simply parse out the arguments and send
23392388 * the command as constructed by the caller */
@@ -2611,18 +2660,18 @@ PHP_METHOD(RedisCluster, bgsave) {
26112660}
26122661/* }}} */
26132662
2614- /* {{{ proto RedisCluster::flushdb(string key)
2615- * proto RedisCluster::flushdb(string host, long port ) */
2663+ /* {{{ proto RedisCluster::flushdb(string key, [bool async] )
2664+ * proto RedisCluster::flushdb(array host_port, [bool async] ) */
26162665PHP_METHOD (RedisCluster , flushdb ) {
2617- cluster_empty_node_cmd (INTERNAL_FUNCTION_PARAM_PASSTHRU , "FLUSHDB" ,
2666+ cluster_flush_cmd (INTERNAL_FUNCTION_PARAM_PASSTHRU , "FLUSHDB" ,
26182667 TYPE_LINE , cluster_bool_resp );
26192668}
26202669/* }}} */
26212670
2622- /* {{{ proto RedisCluster::flushall(string key)
2623- * proto RedisCluster::flushall(string host, long port ) */
2671+ /* {{{ proto RedisCluster::flushall(string key, [bool async] )
2672+ * proto RedisCluster::flushall(array host_port, [bool async] ) */
26242673PHP_METHOD (RedisCluster , flushall ) {
2625- cluster_empty_node_cmd (INTERNAL_FUNCTION_PARAM_PASSTHRU , "FLUSHALL" ,
2674+ cluster_flush_cmd (INTERNAL_FUNCTION_PARAM_PASSTHRU , "FLUSHALL" ,
26262675 TYPE_LINE , cluster_bool_resp );
26272676}
26282677/* }}} */
0 commit comments