@@ -46,6 +46,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ctor, 0, 0, 1)
4646 ZEND_ARG_INFO (0 , timeout )
4747 ZEND_ARG_INFO (0 , read_timeout )
4848 ZEND_ARG_INFO (0 , persistent )
49+ ZEND_ARG_INFO (0 , auth )
4950ZEND_END_ARG_INFO ()
5051
5152ZEND_BEGIN_ARG_INFO_EX (arginfo_del , 0 , 0 , 1 )
@@ -397,8 +398,10 @@ free_cluster_context(zend_object *object)
397398#endif
398399
399400/* Attempt to connect to a Redis cluster provided seeds and timeout options */
400- void redis_cluster_init (redisCluster * c , HashTable * ht_seeds , double timeout ,
401- double read_timeout , int persistent TSRMLS_DC )
401+ static void
402+ redis_cluster_init (redisCluster * c , HashTable * ht_seeds ,
403+ double timeout , double read_timeout , int persistent ,
404+ char * auth , strlen_t auth_len TSRMLS_DC )
402405{
403406 // Validate timeout
404407 if (timeout < 0L || timeout > INT_MAX ) {
@@ -417,6 +420,11 @@ void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double timeout,
417420 zend_throw_exception (redis_cluster_exception_ce ,
418421 "Must pass seeds" , 0 TSRMLS_CC );
419422 }
423+
424+ if (auth && auth_len > 0 ) {
425+ c -> auth = zend_string_init (auth , auth_len , 0 );
426+ }
427+
420428 /* Set our timeout and read_timeout which we'll pass through to the
421429 * socket type operations */
422430 c -> timeout = timeout ;
@@ -438,8 +446,9 @@ void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double timeout,
438446
439447/* Attempt to load a named cluster configured in php.ini */
440448void redis_cluster_load (redisCluster * c , char * name , int name_len TSRMLS_DC ) {
441- zval z_seeds , z_timeout , z_read_timeout , z_persistent , * z_value ;
442- char * iptr ;
449+ zval z_seeds , z_timeout , z_read_timeout , z_persistent , z_auth , * z_value ;
450+ char * iptr , * auth = NULL ;
451+ strlen_t auth_len = 0 ;
443452 double timeout = 0 , read_timeout = 0 ;
444453 int persistent = 0 ;
445454 HashTable * ht_seeds = NULL ;
@@ -500,14 +509,27 @@ void redis_cluster_load(redisCluster *c, char *name, int name_len TSRMLS_DC) {
500509 }
501510 }
502511
512+ /* Cluster auth */
513+ array_init (& z_auth );
514+ if ((iptr = INI_STR ("redis.clusters.auth" )) != NULL ) {
515+ sapi_module .treat_data (PARSE_STRING , estrdup (iptr ), & z_auth TSRMLS_CC );
516+ }
517+ if ((z_value = zend_hash_str_find (Z_ARRVAL (z_auth ), name , name_len )) != NULL &&
518+ Z_TYPE_P (z_value ) == IS_STRING && Z_STRLEN_P (z_value ) > 0
519+ ) {
520+ auth = Z_STRVAL_P (z_value );
521+ auth_len = Z_STRLEN_P (z_value );
522+ }
523+
503524 /* Attempt to create/connect to the cluster */
504- redis_cluster_init (c , ht_seeds , timeout , read_timeout , persistent TSRMLS_CC );
525+ redis_cluster_init (c , ht_seeds , timeout , read_timeout , persistent , auth , auth_len TSRMLS_CC );
505526
506527 /* Clean up our arrays */
507528 zval_dtor (& z_seeds );
508529 zval_dtor (& z_timeout );
509530 zval_dtor (& z_read_timeout );
510531 zval_dtor (& z_persistent );
532+ zval_dtor (& z_auth );
511533}
512534
513535/*
@@ -517,17 +539,17 @@ void redis_cluster_load(redisCluster *c, char *name, int name_len TSRMLS_DC) {
517539/* Create a RedisCluster Object */
518540PHP_METHOD (RedisCluster , __construct ) {
519541 zval * object , * z_seeds = NULL ;
520- char * name ;
521- strlen_t name_len ;
542+ char * name , * auth = NULL ;
543+ strlen_t name_len , auth_len = 0 ;
522544 double timeout = 0.0 , read_timeout = 0.0 ;
523545 zend_bool persistent = 0 ;
524546 redisCluster * context = GET_CONTEXT ();
525547
526548 // Parse arguments
527549 if (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (),
528- "Os!|addb " , & object , redis_cluster_ce , & name ,
529- & name_len , & z_seeds , & timeout ,
530- & read_timeout , & persistent ) == FAILURE )
550+ "Os!|addbs " , & object , redis_cluster_ce , & name ,
551+ & name_len , & z_seeds , & timeout , & read_timeout ,
552+ & persistent , & auth , & auth_len ) == FAILURE )
531553 {
532554 RETURN_FALSE ;
533555 }
@@ -543,7 +565,7 @@ PHP_METHOD(RedisCluster, __construct) {
543565 * to a named cluster, stored in php.ini, otherwise we'll need manual seeds */
544566 if (ZEND_NUM_ARGS () > 1 ) {
545567 redis_cluster_init (context , Z_ARRVAL_P (z_seeds ), timeout , read_timeout ,
546- persistent TSRMLS_CC );
568+ persistent , auth , auth_len TSRMLS_CC );
547569 } else {
548570 redis_cluster_load (context , name , name_len TSRMLS_CC );
549571 }
0 commit comments