Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ece6c1d

Browse files
Failover fix for cluster sessions and srand migration
* We weren't setting the failover member even when specified in the context of a Redis Cluster session. * Moved random number seeding to MINIT so it only ever happens once
1 parent 81cb2bc commit ece6c1d

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

cluster_library.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ PHP_REDIS_API redisCluster *cluster_create(double timeout, double read_timeout,
812812
c->clusterdown = 0;
813813
c->timeout = timeout;
814814
c->read_timeout = read_timeout;
815+
c->failover = failover;
815816

816817
/* Set up our waitms based on timeout */
817818
c->waitms = (long)(1000 * timeout);

redis.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,18 @@ static void add_class_constants(zend_class_entry *ce, int is_cluster TSRMLS_DC)
551551
*/
552552
PHP_MINIT_FUNCTION(redis)
553553
{
554+
struct timeval tv;
555+
554556
zend_class_entry redis_class_entry;
555557
zend_class_entry redis_array_class_entry;
556558
zend_class_entry redis_cluster_class_entry;
557559
zend_class_entry redis_exception_class_entry;
558560
zend_class_entry redis_cluster_exception_class_entry;
559561

562+
/* Seed random generator (for RedisCluster failover) */
563+
gettimeofday(&tv, NULL);
564+
srand(tv.tv_usec * tv.tv_sec);
565+
560566
REGISTER_INI_ENTRIES();
561567

562568
/* Redis class */

redis_cluster.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,6 @@ create_cluster_context(zend_class_entry *class_type TSRMLS_DC) {
266266
redisCluster *cluster;
267267
struct timeval t1;
268268

269-
/* Seed random generator for failover */
270-
gettimeofday(&t1, NULL);
271-
srand(t1.tv_usec * t1.tv_sec);
272-
273269
// Allocate our actual struct
274270
cluster = emalloc(sizeof(redisCluster));
275271
memset(cluster, 0, sizeof(redisCluster));

redis_session.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,10 @@ static void session_conf_timeout(HashTable *ht_conf, const char *key, int key_le
470470
{
471471
zval **z_val;
472472

473-
if (zend_hash_find(ht_conf, key, key_len, (void**)&z_val) == SUCCESS) {
474-
if (Z_TYPE_PP(z_val) == IS_STRING) {
475-
*val = atof(Z_STRVAL_PP(z_val));
476-
} else {
477-
*val = Z_DVAL_PP(z_val);
478-
}
473+
if (zend_hash_find(ht_conf, key, key_len, (void**)&z_val) == SUCCESS &&
474+
Z_TYPE_PP(z_val) == IS_STRING)
475+
{
476+
*val = atof(Z_STRVAL_PP(z_val));
479477
}
480478
}
481479

0 commit comments

Comments
 (0)