From ece6c1d226ebf851bf247ca1b386d964387d21ef Mon Sep 17 00:00:00 2001 From: michael-grunder Date: Thu, 18 Jun 2015 08:09:19 -0700 Subject: 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 --- cluster_library.c | 1 + redis.c | 6 ++++++ redis_cluster.c | 4 ---- redis_session.c | 10 ++++------ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cluster_library.c b/cluster_library.c index b6a760e3..6275080e 100644 --- a/cluster_library.c +++ b/cluster_library.c @@ -812,6 +812,7 @@ PHP_REDIS_API redisCluster *cluster_create(double timeout, double read_timeout, c->clusterdown = 0; c->timeout = timeout; c->read_timeout = read_timeout; + c->failover = failover; /* Set up our waitms based on timeout */ c->waitms = (long)(1000 * timeout); diff --git a/redis.c b/redis.c index 313672ca..75395626 100644 --- a/redis.c +++ b/redis.c @@ -551,12 +551,18 @@ static void add_class_constants(zend_class_entry *ce, int is_cluster TSRMLS_DC) */ PHP_MINIT_FUNCTION(redis) { + struct timeval tv; + zend_class_entry redis_class_entry; zend_class_entry redis_array_class_entry; zend_class_entry redis_cluster_class_entry; zend_class_entry redis_exception_class_entry; zend_class_entry redis_cluster_exception_class_entry; + /* Seed random generator (for RedisCluster failover) */ + gettimeofday(&tv, NULL); + srand(tv.tv_usec * tv.tv_sec); + REGISTER_INI_ENTRIES(); /* Redis class */ diff --git a/redis_cluster.c b/redis_cluster.c index a842b7ca..e51de836 100644 --- a/redis_cluster.c +++ b/redis_cluster.c @@ -266,10 +266,6 @@ create_cluster_context(zend_class_entry *class_type TSRMLS_DC) { redisCluster *cluster; struct timeval t1; - /* Seed random generator for failover */ - gettimeofday(&t1, NULL); - srand(t1.tv_usec * t1.tv_sec); - // Allocate our actual struct cluster = emalloc(sizeof(redisCluster)); memset(cluster, 0, sizeof(redisCluster)); diff --git a/redis_session.c b/redis_session.c index 46bc482b..b935f34d 100644 --- a/redis_session.c +++ b/redis_session.c @@ -470,12 +470,10 @@ static void session_conf_timeout(HashTable *ht_conf, const char *key, int key_le { zval **z_val; - if (zend_hash_find(ht_conf, key, key_len, (void**)&z_val) == SUCCESS) { - if (Z_TYPE_PP(z_val) == IS_STRING) { - *val = atof(Z_STRVAL_PP(z_val)); - } else { - *val = Z_DVAL_PP(z_val); - } + if (zend_hash_find(ht_conf, key, key_len, (void**)&z_val) == SUCCESS && + Z_TYPE_PP(z_val) == IS_STRING) + { + *val = atof(Z_STRVAL_PP(z_val)); } } -- cgit v1.2.3