@@ -2221,32 +2221,43 @@ PHP_METHOD(RedisCluster, discard) {
2221
2221
static short
2222
2222
cluster_cmd_get_slot (redisCluster * c , zval * z_arg TSRMLS_DC )
2223
2223
{
2224
+ int key_len , key_free ;
2225
+ zval * * z_host , * * z_port , * z_tmp = NULL ;
2224
2226
short slot ;
2227
+ char * key ;
2225
2228
2226
2229
/* If it's a string, treat it as a key. Otherwise, look for a two
2227
2230
* 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 );
2231
2245
2232
2246
/* Hash it */
2233
2247
key_free = redis_key_prefix (c -> flags , & key , & key_len );
2234
2248
slot = cluster_hash_key (key , key_len );
2235
2249
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
- }
2249
2250
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
+ {
2250
2261
/* Attempt to find this specific node by host:port */
2251
2262
slot = cluster_find_slot (c ,(const char * )Z_STRVAL_PP (z_host ),
2252
2263
(unsigned short )Z_LVAL_PP (z_port ));
@@ -2256,6 +2267,10 @@ cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
2256
2267
php_error_docref (0 TSRMLS_CC , E_WARNING , "Unknown node %s:%ld" ,
2257
2268
Z_STRVAL_PP (z_host ), Z_LVAL_PP (z_port ));
2258
2269
}
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 ;
2259
2274
}
2260
2275
2261
2276
return slot ;
@@ -2618,8 +2633,10 @@ PHP_METHOD(RedisCluster, lastsave) {
2618
2633
* proto array RedisCluster::info(array host_port, [string $arg]) */
2619
2634
PHP_METHOD (RedisCluster , info ) {
2620
2635
redisCluster * c = GET_CONTEXT ();
2636
+ REDIS_REPLY_TYPE rtype ;
2621
2637
char * cmd , * opt = NULL ;
2622
2638
int cmd_len , opt_len ;
2639
+ void * ctx = NULL ;
2623
2640
zval * z_arg ;
2624
2641
short slot ;
2625
2642
@@ -2643,14 +2660,19 @@ PHP_METHOD(RedisCluster, info) {
2643
2660
cmd_len = redis_cmd_format_static (& cmd , "INFO" , "" );
2644
2661
}
2645
2662
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 ) {
2647
2665
zend_throw_exception (redis_cluster_exception_ce ,
2648
2666
"Unable to send INFO command to specific node" , 0 TSRMLS_CC );
2649
2667
efree (cmd );
2650
2668
RETURN_FALSE ;
2651
2669
}
2652
2670
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
+ }
2654
2676
2655
2677
efree (cmd );
2656
2678
}
0 commit comments