@@ -2221,32 +2221,43 @@ PHP_METHOD(RedisCluster, discard) {
22212221static short
22222222cluster_cmd_get_slot (redisCluster * c , zval * z_arg TSRMLS_DC )
22232223{
2224+ int key_len , key_free ;
2225+ zval * * z_host , * * z_port , * z_tmp = NULL ;
22242226 short slot ;
2227+ char * key ;
22252228
22262229 /* If it's a string, treat it as a key. Otherwise, look for a two
22272230 * element array */
2228- if (Z_TYPE_P (z_arg )== IS_STRING ) {
2229- char * key = Z_STRVAL_P (z_arg );
2230- int key_len = Z_STRLEN_P (z_arg ), key_free ;
2231+ if (Z_TYPE_P (z_arg )== IS_STRING || Z_TYPE_P (z_arg )== IS_LONG ||
2232+ Z_TYPE_P (z_arg )== IS_DOUBLE )
2233+ {
2234+ /* Allow for any scalar here */
2235+ if (Z_TYPE_P (z_arg ) != IS_STRING ) {
2236+ MAKE_STD_ZVAL (z_tmp );
2237+ * z_tmp = * z_arg ;
2238+ zval_copy_ctor (z_tmp );
2239+ convert_to_string (z_tmp );
2240+ z_arg = z_tmp ;
2241+ }
2242+
2243+ key = Z_STRVAL_P (z_arg );
2244+ key_len = Z_STRLEN_P (z_arg );
22312245
22322246 /* Hash it */
22332247 key_free = redis_key_prefix (c -> flags , & key , & key_len );
22342248 slot = cluster_hash_key (key , key_len );
22352249 if (key_free ) efree (key );
2236- } else {
2237- zval * * z_host , * * z_port ;
2238-
2239- /* We'll need two elements, one string, one long */
2240- if (Z_TYPE_P (z_arg ) != IS_ARRAY ||
2241- zend_hash_index_find (Z_ARRVAL_P (z_arg ),0 ,(void * * )& z_host )== FAILURE ||
2242- zend_hash_index_find (Z_ARRVAL_P (z_arg ),1 ,(void * * )& z_port )== FAILURE ||
2243- Z_TYPE_PP (z_host )!= IS_STRING || Z_TYPE_PP (z_port )!= IS_LONG )
2244- {
2245- php_error_docref (0 TSRMLS_CC , E_WARNING ,
2246- "Directed commands must be passed string key or [host,port]" );
2247- return -1 ;
2248- }
22492250
2251+ /* Destroy our temp value if we had to convert it */
2252+ if (z_tmp ) {
2253+ zval_dtor (z_tmp );
2254+ efree (z_tmp );
2255+ }
2256+ } else if (Z_TYPE_P (z_arg ) == IS_ARRAY &&
2257+ zend_hash_index_find (Z_ARRVAL_P (z_arg ),0 ,(void * * )& z_host )!= FAILURE &&
2258+ zend_hash_index_find (Z_ARRVAL_P (z_arg ),1 ,(void * * )& z_port )!= FAILURE &&
2259+ Z_TYPE_PP (z_host )== IS_STRING && Z_TYPE_PP (z_port )== IS_LONG )
2260+ {
22502261 /* Attempt to find this specific node by host:port */
22512262 slot = cluster_find_slot (c ,(const char * )Z_STRVAL_PP (z_host ),
22522263 (unsigned short )Z_LVAL_PP (z_port ));
@@ -2256,6 +2267,10 @@ cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
22562267 php_error_docref (0 TSRMLS_CC , E_WARNING , "Unknown node %s:%ld" ,
22572268 Z_STRVAL_PP (z_host ), Z_LVAL_PP (z_port ));
22582269 }
2270+ } else {
2271+ php_error_docref (0 TSRMLS_CC , E_WARNING ,
2272+ "Direted commands musty be passed a key or [host,port] array" );
2273+ return -1 ;
22592274 }
22602275
22612276 return slot ;
@@ -2618,8 +2633,10 @@ PHP_METHOD(RedisCluster, lastsave) {
26182633 * proto array RedisCluster::info(array host_port, [string $arg]) */
26192634PHP_METHOD (RedisCluster , info ) {
26202635 redisCluster * c = GET_CONTEXT ();
2636+ REDIS_REPLY_TYPE rtype ;
26212637 char * cmd , * opt = NULL ;
26222638 int cmd_len , opt_len ;
2639+ void * ctx = NULL ;
26232640 zval * z_arg ;
26242641 short slot ;
26252642
@@ -2643,14 +2660,19 @@ PHP_METHOD(RedisCluster, info) {
26432660 cmd_len = redis_cmd_format_static (& cmd , "INFO" , "" );
26442661 }
26452662
2646- if (cluster_send_slot (c , slot , cmd , cmd_len , TYPE_BULK TSRMLS_CC )< 0 ) {
2663+ rtype = CLUSTER_IS_ATOMIC (c ) ? TYPE_BULK : TYPE_LINE ;
2664+ if (cluster_send_slot (c , slot , cmd , cmd_len , rtype TSRMLS_CC )< 0 ) {
26472665 zend_throw_exception (redis_cluster_exception_ce ,
26482666 "Unable to send INFO command to specific node" , 0 TSRMLS_CC );
26492667 efree (cmd );
26502668 RETURN_FALSE ;
26512669 }
26522670
2653- cluster_info_resp (INTERNAL_FUNCTION_PARAM_PASSTHRU , c , NULL );
2671+ if (CLUSTER_IS_ATOMIC (c )) {
2672+ cluster_info_resp (INTERNAL_FUNCTION_PARAM_PASSTHRU , c , NULL );
2673+ } else {
2674+ CLUSTER_ENQUEUE_RESPONSE (c , slot , cluster_info_resp , ctx );
2675+ }
26542676
26552677 efree (cmd );
26562678}
0 commit comments