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:
authormichael-grunder <michael.grunder@gmail.com>2019-05-29 19:42:29 +0300
committerMichael Grunder <michael.grunder@gmail.com>2019-06-03 17:53:21 +0300
commit6e4941706835d32bfce6b2843f791ef9720b7b88 (patch)
tree574bb6a1089bafdf38d034c366053176266b3474 /redis_cluster.c
parent19f3efcfe6e1a32451a543fa186a8f38d250d941 (diff)
Allow PING to take an optional argument.
Addresses #1563
Diffstat (limited to 'redis_cluster.c')
-rw-r--r--redis_cluster.c66
1 files changed, 62 insertions, 4 deletions
diff --git a/redis_cluster.c b/redis_cluster.c
index b952cc4b..0342096c 100644
--- a/redis_cluster.c
+++ b/redis_cluster.c
@@ -3002,11 +3002,69 @@ PHP_METHOD(RedisCluster, randomkey) {
}
/* }}} */
-/* {{{ proto bool RedisCluster::ping(string key)
- * proto bool RedisCluster::ping(array host_port) */
+/* {{{ proto bool RedisCluster::ping(string key| string msg)
+ * proto bool RedisCluster::ping(array host_port| string msg) */
PHP_METHOD(RedisCluster, ping) {
- cluster_empty_node_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PING",
- TYPE_LINE, cluster_ping_resp);
+ redisCluster *c = GET_CONTEXT();
+ REDIS_REPLY_TYPE rtype;
+ void *ctx = NULL;
+ zval *z_node;
+ char *cmd, *arg = NULL;
+ int cmdlen;
+ size_t arglen;
+ short slot;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s!", &z_node, &arg,
+ &arglen) == FAILURE)
+ {
+ RETURN_FALSE;
+ }
+
+ /* Treat this as a readonly command */
+ c->readonly = CLUSTER_IS_ATOMIC(c);
+
+ /* Grab slot either by key or host/port */
+ slot = cluster_cmd_get_slot(c, z_node TSRMLS_CC);
+ if (slot < 0) {
+ RETURN_FALSE;
+ }
+
+ /* Construct our command */
+ if (arg != NULL) {
+ cmdlen = redis_spprintf(NULL, NULL TSRMLS_CC, &cmd, "PING", "s", arg, arglen);
+ } else {
+ cmdlen = redis_spprintf(NULL, NULL TSRMLS_CC, &cmd, "PING", "");
+ }
+
+ /* Send it off */
+ rtype = CLUSTER_IS_ATOMIC(c) && arg != NULL ? TYPE_BULK : TYPE_LINE;
+ if (cluster_send_slot(c, slot, cmd, cmdlen, rtype TSRMLS_CC) < 0) {
+ CLUSTER_THROW_EXCEPTION("Unable to send commnad at the specificed node", 0);
+ efree(cmd);
+ RETURN_FALSE;
+ }
+
+ /* We're done with our command */
+ efree(cmd);
+
+ /* Process response */
+ if (CLUSTER_IS_ATOMIC(c)) {
+ if (arg != NULL) {
+ cluster_bulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
+ } else {
+ /* If we're atomic and didn't send an argument then we have already
+ * processed the reply (which must have been successful. */
+ RETURN_TRUE;
+ }
+ } else {
+ if (arg != NULL) {
+ CLUSTER_ENQUEUE_RESPONSE(c, slot, cluster_bulk_resp, ctx);
+ } else {
+ CLUSTER_ENQUEUE_RESPONSE(c, slot, cluster_variant_resp, ctx);
+ }
+
+ RETURN_ZVAL(getThis(), 1, 0);
+ }
}
/* }}} */