@@ -3002,11 +3002,69 @@ PHP_METHOD(RedisCluster, randomkey) {
30023002}
30033003/* }}} */
30043004
3005- /* {{{ proto bool RedisCluster::ping(string key)
3006- * proto bool RedisCluster::ping(array host_port) */
3005+ /* {{{ proto bool RedisCluster::ping(string key| string msg )
3006+ * proto bool RedisCluster::ping(array host_port| string msg ) */
30073007PHP_METHOD (RedisCluster , ping ) {
3008- cluster_empty_node_cmd (INTERNAL_FUNCTION_PARAM_PASSTHRU , "PING" ,
3009- TYPE_LINE , cluster_ping_resp );
3008+ redisCluster * c = GET_CONTEXT ();
3009+ REDIS_REPLY_TYPE rtype ;
3010+ void * ctx = NULL ;
3011+ zval * z_node ;
3012+ char * cmd , * arg = NULL ;
3013+ int cmdlen ;
3014+ size_t arglen ;
3015+ short slot ;
3016+
3017+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "z|s!" , & z_node , & arg ,
3018+ & arglen ) == FAILURE )
3019+ {
3020+ RETURN_FALSE ;
3021+ }
3022+
3023+ /* Treat this as a readonly command */
3024+ c -> readonly = CLUSTER_IS_ATOMIC (c );
3025+
3026+ /* Grab slot either by key or host/port */
3027+ slot = cluster_cmd_get_slot (c , z_node TSRMLS_CC );
3028+ if (slot < 0 ) {
3029+ RETURN_FALSE ;
3030+ }
3031+
3032+ /* Construct our command */
3033+ if (arg != NULL ) {
3034+ cmdlen = redis_spprintf (NULL , NULL TSRMLS_CC , & cmd , "PING" , "s" , arg , arglen );
3035+ } else {
3036+ cmdlen = redis_spprintf (NULL , NULL TSRMLS_CC , & cmd , "PING" , "" );
3037+ }
3038+
3039+ /* Send it off */
3040+ rtype = CLUSTER_IS_ATOMIC (c ) && arg != NULL ? TYPE_BULK : TYPE_LINE ;
3041+ if (cluster_send_slot (c , slot , cmd , cmdlen , rtype TSRMLS_CC ) < 0 ) {
3042+ CLUSTER_THROW_EXCEPTION ("Unable to send commnad at the specificed node" , 0 );
3043+ efree (cmd );
3044+ RETURN_FALSE ;
3045+ }
3046+
3047+ /* We're done with our command */
3048+ efree (cmd );
3049+
3050+ /* Process response */
3051+ if (CLUSTER_IS_ATOMIC (c )) {
3052+ if (arg != NULL ) {
3053+ cluster_bulk_resp (INTERNAL_FUNCTION_PARAM_PASSTHRU , c , NULL );
3054+ } else {
3055+ /* If we're atomic and didn't send an argument then we have already
3056+ * processed the reply (which must have been successful. */
3057+ RETURN_TRUE ;
3058+ }
3059+ } else {
3060+ if (arg != NULL ) {
3061+ CLUSTER_ENQUEUE_RESPONSE (c , slot , cluster_bulk_resp , ctx );
3062+ } else {
3063+ CLUSTER_ENQUEUE_RESPONSE (c , slot , cluster_variant_resp , ctx );
3064+ }
3065+
3066+ RETURN_ZVAL (getThis (), 1 , 0 );
3067+ }
30103068}
30113069/* }}} */
30123070
0 commit comments