@@ -264,7 +264,6 @@ zend_object_value
264264create_cluster_context (zend_class_entry * class_type TSRMLS_DC ) {
265265 zend_object_value retval ;
266266 redisCluster * cluster ;
267- struct timeval t1 ;
268267
269268 // Allocate our actual struct
270269 cluster = emalloc (sizeof (redisCluster ));
@@ -333,7 +332,7 @@ void free_cluster_context(void *object TSRMLS_DC) {
333332
334333/* Attempt to connect to a Redis cluster provided seeds and timeout options */
335334void redis_cluster_init (redisCluster * c , HashTable * ht_seeds , double timeout ,
336- double read_timeout TSRMLS_DC )
335+ double read_timeout , int persistent TSRMLS_DC )
337336{
338337 // Validate timeout
339338 if (timeout < 0L || timeout > INT_MAX ) {
@@ -357,6 +356,9 @@ void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double timeout,
357356 * socket type operations */
358357 c -> timeout = timeout ;
359358 c -> read_timeout = read_timeout ;
359+
360+ /* Set our option to use or not use persistent connections */
361+ c -> persistent = persistent ;
360362
361363 /* Calculate the number of miliseconds we will wait when bouncing around,
362364 * (e.g. a node goes down), which is not the same as a standard timeout. */
@@ -371,9 +373,10 @@ void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double timeout,
371373
372374/* Attempt to load a named cluster configured in php.ini */
373375void redis_cluster_load (redisCluster * c , char * name , int name_len TSRMLS_DC ) {
374- zval * z_seeds , * z_timeout , * z_read_timeout , * * z_value ;
376+ zval * z_seeds , * z_timeout , * z_read_timeout , * z_persistent , * * z_value ;
375377 char * iptr ;
376378 double timeout = 0 , read_timeout = 0 ;
379+ int persistent = 0 ;
377380 HashTable * ht_seeds = NULL ;
378381
379382 /* Seeds */
@@ -415,8 +418,21 @@ void redis_cluster_load(redisCluster *c, char *name, int name_len TSRMLS_DC) {
415418 }
416419 }
417420
421+ /* Persistent connections */
422+ MAKE_STD_ZVAL (z_persistent );
423+ array_init (z_persistent );
424+ iptr = estrdup (INI_STR ("redis.clusters.persistent" ));
425+ sapi_module .treat_data (PARSE_STRING , iptr , z_persistent TSRMLS_CC );
426+ if (zend_hash_find (Z_ARRVAL_P (z_persistent ), name , name_len + 1 , (void * * )& z_value ) != FAILURE ) {
427+ if (Z_TYPE_PP (z_value ) == IS_STRING ) {
428+ persistent = atoi (Z_STRVAL_PP (z_value ));
429+ } else if (Z_TYPE_PP (z_value ) == IS_LONG ) {
430+ persistent = Z_LVAL_PP (z_value );
431+ }
432+ }
433+
418434 /* Attempt to create/connect to the cluster */
419- redis_cluster_init (c , ht_seeds , timeout , read_timeout TSRMLS_CC );
435+ redis_cluster_init (c , ht_seeds , timeout , read_timeout , persistent TSRMLS_CC );
420436
421437 /* Clean up our arrays */
422438 zval_dtor (z_seeds );
@@ -437,13 +453,14 @@ PHP_METHOD(RedisCluster, __construct) {
437453 char * name ;
438454 long name_len ;
439455 double timeout = 0.0 , read_timeout = 0.0 ;
456+ zend_bool persistent = 0 ;
440457 redisCluster * context = GET_CONTEXT ();
441458
442459 // Parse arguments
443460 if (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (),
444- "Os|add " , & object , redis_cluster_ce , & name ,
461+ "Os|addb " , & object , redis_cluster_ce , & name ,
445462 & name_len , & z_seeds , & timeout ,
446- & read_timeout )== FAILURE )
463+ & read_timeout , & persistent )== FAILURE )
447464 {
448465 RETURN_FALSE ;
449466 }
@@ -458,8 +475,8 @@ PHP_METHOD(RedisCluster, __construct) {
458475 /* If we've been passed only one argument, the user is attempting to connect
459476 * to a named cluster, stored in php.ini, otherwise we'll need manual seeds */
460477 if (ZEND_NUM_ARGS () > 1 ) {
461- redis_cluster_init (context , Z_ARRVAL_P (z_seeds ), timeout , read_timeout
462- TSRMLS_CC );
478+ redis_cluster_init (context , Z_ARRVAL_P (z_seeds ), timeout , read_timeout ,
479+ persistent TSRMLS_CC );
463480 } else {
464481 redis_cluster_load (context , name , name_len TSRMLS_CC );
465482 }
0 commit comments