Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichael-grunder <michael.grunder@gmail.com>2015-06-18 18:09:19 +0300
committermichael-grunder <michael.grunder@gmail.com>2015-06-18 18:09:19 +0300
commitece6c1d226ebf851bf247ca1b386d964387d21ef (patch)
tree66d8fc9e02e8f9e331b41e4cf569c59f960263d7
parent81cb2bcc2fd47f9976adc41d73d180cab80b20c0 (diff)
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
-rw-r--r--cluster_library.c1
-rw-r--r--redis.c6
-rw-r--r--redis_cluster.c4
-rw-r--r--redis_session.c10
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));
}
}