@@ -264,7 +264,6 @@ zend_object_value
264
264
create_cluster_context (zend_class_entry * class_type TSRMLS_DC ) {
265
265
zend_object_value retval ;
266
266
redisCluster * cluster ;
267
- struct timeval t1 ;
268
267
269
268
// Allocate our actual struct
270
269
cluster = emalloc (sizeof (redisCluster ));
@@ -333,7 +332,7 @@ void free_cluster_context(void *object TSRMLS_DC) {
333
332
334
333
/* Attempt to connect to a Redis cluster provided seeds and timeout options */
335
334
void redis_cluster_init (redisCluster * c , HashTable * ht_seeds , double timeout ,
336
- double read_timeout TSRMLS_DC )
335
+ double read_timeout , int persistent TSRMLS_DC )
337
336
{
338
337
// Validate timeout
339
338
if (timeout < 0L || timeout > INT_MAX ) {
@@ -357,6 +356,9 @@ void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double timeout,
357
356
* socket type operations */
358
357
c -> timeout = timeout ;
359
358
c -> read_timeout = read_timeout ;
359
+
360
+ /* Set our option to use or not use persistent connections */
361
+ c -> persistent = persistent ;
360
362
361
363
/* Calculate the number of miliseconds we will wait when bouncing around,
362
364
* (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,
371
373
372
374
/* Attempt to load a named cluster configured in php.ini */
373
375
void 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 ;
375
377
char * iptr ;
376
378
double timeout = 0 , read_timeout = 0 ;
379
+ int persistent = 0 ;
377
380
HashTable * ht_seeds = NULL ;
378
381
379
382
/* Seeds */
@@ -415,8 +418,21 @@ void redis_cluster_load(redisCluster *c, char *name, int name_len TSRMLS_DC) {
415
418
}
416
419
}
417
420
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
+
418
434
/* 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 );
420
436
421
437
/* Clean up our arrays */
422
438
zval_dtor (z_seeds );
@@ -437,13 +453,14 @@ PHP_METHOD(RedisCluster, __construct) {
437
453
char * name ;
438
454
long name_len ;
439
455
double timeout = 0.0 , read_timeout = 0.0 ;
456
+ zend_bool persistent = 0 ;
440
457
redisCluster * context = GET_CONTEXT ();
441
458
442
459
// Parse arguments
443
460
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 ,
445
462
& name_len , & z_seeds , & timeout ,
446
- & read_timeout )== FAILURE )
463
+ & read_timeout , & persistent )== FAILURE )
447
464
{
448
465
RETURN_FALSE ;
449
466
}
@@ -458,8 +475,8 @@ PHP_METHOD(RedisCluster, __construct) {
458
475
/* If we've been passed only one argument, the user is attempting to connect
459
476
* to a named cluster, stored in php.ini, otherwise we'll need manual seeds */
460
477
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 );
463
480
} else {
464
481
redis_cluster_load (context , name , name_len TSRMLS_CC );
465
482
}
0 commit comments