1616  | Original author: Alfonso Jimenez <[email protected] >             | 1717  | Maintainer: Nicolas Favre-Felix <[email protected] >           | 1818  | Maintainer: Nasreddine Bouafif <[email protected] >                | 19+   | Maintainer: Michael Grunder <[email protected]                | 1920  +----------------------------------------------------------------------+ 
2021*/ 
2122
@@ -227,6 +228,7 @@ static zend_function_entry redis_functions[] = {
227228     PHP_ME (Redis , _prefix , NULL , ZEND_ACC_PUBLIC )
228229     PHP_ME (Redis , _unserialize , NULL , ZEND_ACC_PUBLIC )
229230
231+      PHP_ME (Redis , client , NULL , ZEND_ACC_PUBLIC )
230232
231233     /* options */ 
232234     PHP_ME (Redis , getOption , NULL , ZEND_ACC_PUBLIC )
@@ -554,7 +556,7 @@ PHP_METHOD(Redis,__destruct) {
554556	}
555557}
556558
557- /* {{{ proto boolean Redis::connect(string host, int port [, double timeout]) 
559+ /* {{{ proto boolean Redis::connect(string host, int port [, double timeout [, long retry_interval] ]) 
558560 */ 
559561PHP_METHOD (Redis , connect )
560562{
@@ -590,6 +592,7 @@ PHPAPI int redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
590592	int  host_len , id ;
591593	char  * host  =  NULL ;
592594	long  port  =  -1 ;
595+ 	long  retry_interval  =  0 ;
593596
594597	char  * persistent_id  =  NULL ;
595598	int  persistent_id_len  =  -1 ;
@@ -602,9 +605,10 @@ PHPAPI int redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
602605    persistent  =  0 ;
603606#endif 
604607
605- 	if  (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "Os|lds " ,
608+ 	if  (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "Os|ldsl " ,
606609				& object , redis_ce , & host , & host_len , & port ,
607- 				& timeout , & persistent_id , & persistent_id_len ) ==  FAILURE ) {
610+ 				& timeout , & persistent_id , & persistent_id_len ,
611+ 				& retry_interval ) ==  FAILURE ) {
608612		return  FAILURE ;
609613	}
610614
@@ -613,6 +617,11 @@ PHPAPI int redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
613617		return  FAILURE ;
614618	}
615619
620+ 	if  (retry_interval  <  0L  ||  retry_interval  >  INT_MAX ) {
621+ 		zend_throw_exception (redis_exception_ce , "Invalid retry interval" , 0  TSRMLS_CC );
622+ 		return  FAILURE ;
623+ 	}
624+ 
616625	if (port  ==  -1  &&  host_len  &&  host [0 ] !=  '/' ) { /* not unix socket, set to default value */ 
617626		port  =  6379 ;
618627	}
@@ -629,7 +638,7 @@ PHPAPI int redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
629638		zend_clear_exception (TSRMLS_C ); /* clear exception triggered by non-existent socket during connect(). */ 
630639	}
631640
632- 	redis_sock  =  redis_sock_create (host , host_len , port , timeout , persistent , persistent_id );
641+ 	redis_sock  =  redis_sock_create (host , host_len , port , timeout , persistent , persistent_id ,  retry_interval );
633642
634643	if  (redis_sock_server_open (redis_sock , 1  TSRMLS_CC ) <  0 ) {
635644		redis_free_socket (redis_sock );
@@ -6456,5 +6465,56 @@ PHP_METHOD(Redis, getAuth) {
64566465    }
64576466}
64586467
6459- /* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */ 
6468+ /* 
6469+  * $redis->client('list'); 
6470+  * $redis->client('kill', <ip:port>); 
6471+  * $redis->client('setname', <name>); 
6472+  * $redis->client('getname'); 
6473+  */ 
6474+ PHP_METHOD (Redis , client ) {
6475+     zval  * object ;
6476+     RedisSock  * redis_sock ;
6477+     char  * cmd , * opt = NULL , * arg = NULL ;
6478+     int  cmd_len , opt_len , arg_len ;
6479+ 
6480+     // Parse our method parameters 
6481+     if (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "Os|s" , 
6482+         & object , redis_ce , & opt , & opt_len , & arg , & arg_len ) ==  FAILURE ) 
6483+     {
6484+         RETURN_FALSE ;
6485+     }
6486+ 
6487+     // Grab our socket 
6488+     if (redis_sock_get (object , & redis_sock  TSRMLS_CC , 0 ) <  0 ) {
6489+         RETURN_FALSE ;
6490+     }
6491+ 
6492+     // Build our CLIENT command 
6493+     if (ZEND_NUM_ARGS () ==  2 ) {
6494+         cmd_len  =  redis_cmd_format_static (& cmd , "CLIENT" , "ss" , opt , opt_len ,
6495+                                           arg , arg_len ); 
6496+     } else  {
6497+         cmd_len  =  redis_cmd_format_static (& cmd , "CLIENT" , "s" , opt , opt_len );
6498+     }
6499+ 
6500+     // Handle CLIENT LIST specifically 
6501+     int  is_list  =  !strncasecmp (opt , "list" , 4 );
6502+ 
6503+     // Execute our queue command 
6504+     REDIS_PROCESS_REQUEST (redis_sock , cmd , cmd_len );
6505+ 
6506+     // We handle CLIENT LIST with a custom response function 
6507+     if (!strncasecmp (opt , "list" , 4 )) {
6508+         IF_ATOMIC () {
6509+             redis_client_list_reply (INTERNAL_FUNCTION_PARAM_PASSTHRU ,redis_sock ,NULL );
6510+         }
6511+         REDIS_PROCESS_RESPONSE (redis_client_list_reply );
6512+     } else  {
6513+         IF_ATOMIC () {
6514+             redis_read_variant_reply (INTERNAL_FUNCTION_PARAM_PASSTHRU ,redis_sock ,NULL );
6515+         }
6516+         REDIS_PROCESS_RESPONSE (redis_read_variant_reply );
6517+     }
6518+ }
64606519
6520+ /* vim: set tabstop=4 softtabstops=4 noexpandtab shiftwidth=4: */ 
0 commit comments