Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.h4
-rw-r--r--redis.c4
-rw-r--r--redis_array.c4
-rw-r--r--redis_cluster.c65
4 files changed, 65 insertions, 12 deletions
diff --git a/common.h b/common.h
index 1843e85a..f2062a9e 100644
--- a/common.h
+++ b/common.h
@@ -1092,8 +1092,4 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_georadiusbymember, 0, 0, 4)
ZEND_ARG_ARRAY_INFO(0, opts, 0)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_flush, 0, 0, 0)
- ZEND_ARG_INFO(0, async)
-ZEND_END_ARG_INFO()
-
#endif
diff --git a/redis.c b/redis.c
index afbe7d86..f40dc0d1 100644
--- a/redis.c
+++ b/redis.c
@@ -108,6 +108,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_config, 0, 0, 2)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_flush, 0, 0, 0)
+ ZEND_ARG_INFO(0, async)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_pubsub, 0, 0, 1)
ZEND_ARG_INFO(0, cmd)
#if PHP_VERSION_ID >= 50600
diff --git a/redis_array.c b/redis_array.c
index 3d7f9366..9f00a74c 100644
--- a/redis_array.c
+++ b/redis_array.c
@@ -97,6 +97,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_multi, 0, 0, 1)
ZEND_ARG_INFO(0, mode)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_flush, 0, 0, 0)
+ ZEND_ARG_INFO(0, async)
+ZEND_END_ARG_INFO()
+
zend_function_entry redis_array_functions[] = {
PHP_ME(RedisArray, __call, arginfo_call, ZEND_ACC_PUBLIC)
PHP_ME(RedisArray, __construct, arginfo_ctor, ZEND_ACC_PUBLIC)
diff --git a/redis_cluster.c b/redis_cluster.c
index 8b802011..9b33d435 100644
--- a/redis_cluster.c
+++ b/redis_cluster.c
@@ -84,6 +84,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_info, 0, 0, 1)
ZEND_ARG_INFO(0, option)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_flush, 0, 0, 1)
+ ZEND_ARG_INFO(0, key_or_address)
+ ZEND_ARG_INFO(0, async)
+ZEND_END_ARG_INFO()
+
/* Argument info for HSCAN, SSCAN, HSCAN */
ZEND_BEGIN_ARG_INFO_EX(arginfo_kscan_cl, 0, 0, 2)
ZEND_ARG_INFO(0, str_key)
@@ -136,8 +141,8 @@ zend_function_entry redis_cluster_functions[] = {
PHP_ME(RedisCluster, exists, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, expire, arginfo_expire, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, expireat, arginfo_key_timestamp, ZEND_ACC_PUBLIC)
- PHP_ME(RedisCluster, flushall, arginfo_key_or_address, ZEND_ACC_PUBLIC)
- PHP_ME(RedisCluster, flushdb, arginfo_key_or_address, ZEND_ACC_PUBLIC)
+ PHP_ME(RedisCluster, flushall, arginfo_flush, ZEND_ACC_PUBLIC)
+ PHP_ME(RedisCluster, flushdb, arginfo_flush, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, geoadd, arginfo_geoadd, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, geodist, arginfo_geodist, ZEND_ACC_PUBLIC)
PHP_ME(RedisCluster, geohash, arginfo_key_members, ZEND_ACC_PUBLIC)
@@ -2334,6 +2339,50 @@ cluster_empty_node_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw,
efree(cmd);
}
+static void
+cluster_flush_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, REDIS_REPLY_TYPE reply_type, cluster_cb cb)
+{
+ redisCluster *c = GET_CONTEXT();
+ char *cmd;
+ int cmd_len;
+ zval *z_arg;
+ zend_bool async = 0;
+ short slot;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &z_arg, &async) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ // One argument means find the node (treated like a key), and two means
+ // send the command to a specific host and port
+ slot = cluster_cmd_get_slot(c, z_arg TSRMLS_CC);
+ if (slot < 0) {
+ RETURN_FALSE;
+ }
+
+ // Construct our command
+ if (async) {
+ cmd_len = redis_spprintf(NULL, NULL TSRMLS_CC, &cmd, kw, "s", "ASYNC", sizeof("ASYNC") - 1);
+ } else {
+ cmd_len = redis_spprintf(NULL, NULL TSRMLS_CC, &cmd, kw, "");
+ }
+
+
+ // Kick off our command
+ if (cluster_send_slot(c, slot, cmd, cmd_len, reply_type TSRMLS_CC) < 0) {
+ zend_throw_exception(redis_cluster_exception_ce,
+ "Unable to send command at a specific node", 0 TSRMLS_CC);
+ efree(cmd);
+ RETURN_FALSE;
+ }
+
+ // Our response callback
+ cb(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
+
+ // Free our command
+ efree(cmd);
+}
+
/* Generic routine for handling various commands which need to be directed at
* a node, but have complex syntax. We simply parse out the arguments and send
* the command as constructed by the caller */
@@ -2611,18 +2660,18 @@ PHP_METHOD(RedisCluster, bgsave) {
}
/* }}} */
-/* {{{ proto RedisCluster::flushdb(string key)
- * proto RedisCluster::flushdb(string host, long port) */
+/* {{{ proto RedisCluster::flushdb(string key, [bool async])
+ * proto RedisCluster::flushdb(array host_port, [bool async]) */
PHP_METHOD(RedisCluster, flushdb) {
- cluster_empty_node_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "FLUSHDB",
+ cluster_flush_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "FLUSHDB",
TYPE_LINE, cluster_bool_resp);
}
/* }}} */
-/* {{{ proto RedisCluster::flushall(string key)
- * proto RedisCluster::flushall(string host, long port) */
+/* {{{ proto RedisCluster::flushall(string key, [bool async])
+ * proto RedisCluster::flushall(array host_port, [bool async]) */
PHP_METHOD(RedisCluster, flushall) {
- cluster_empty_node_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "FLUSHALL",
+ cluster_flush_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "FLUSHALL",
TYPE_LINE, cluster_bool_resp);
}
/* }}} */