Skip to content

Commit 9ef2ed8

Browse files
pool challenge doesn't need cryptographic security
* Use PHP's regular php_rand() function instead of mt_rand() because we don't need cryptographic security for the test, and mt_rand() will seed for us if it's unseeded. * Adds a cluster test that should retreive connections from the pool.
1 parent 0cee8f7 commit 9ef2ed8

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

library.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,11 +1813,7 @@ redis_sock_check_liveness(RedisSock *redis_sock)
18131813
}
18141814

18151815
gettimeofday(&tv, NULL);
1816-
if (!BG(mt_rand_is_seeded)) {
1817-
php_mt_srand(GENERATE_SEED());
1818-
}
1819-
1820-
uniqid_len = snprintf(uniqid, sizeof(uniqid), "phpredis_pool:%08lx%05lx:%08" PRIx32, (long)tv.tv_sec, (long)tv.tv_usec, php_mt_rand());
1816+
uniqid_len = snprintf(uniqid, sizeof(uniqid), "phpredis_pool:%08lx%05lx:%08lx", (long)tv.tv_sec, (long)tv.tv_usec, (long)php_rand());
18211817
redis_cmd_init_sstr(&cmd, 1, "ECHO", sizeof("ECHO") - 1);
18221818
redis_cmd_append_sstr(&cmd, uniqid, uniqid_len);
18231819
smart_string_0(&cmd);

tests/RedisClusterTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,21 @@ public function testSlotCache() {
665665
ini_set('redis.clusters.cache_slots', 0);
666666
}
667667

668+
/* Regression test for connection pool liveness checks */
669+
public function testConnectionPool() {
670+
$prev_value = ini_get('redis.pconnect.pooling_enabled');
671+
ini_set('redis.pconnect.pooling_enabled', 1);
672+
673+
$pong = 0;
674+
for ($i = 0; $i < 10; $i++) {
675+
$obj_rc = new RedisCluster(NULL, self::$_arr_node_map, 30, 30, true);
676+
$pong += $obj_rc->ping("key:$i");
677+
}
678+
679+
$this->assertEquals($pong, $i);
680+
ini_set('redis.pconnect.pooling_enabled', $prev_value);
681+
}
682+
668683
/**
669684
* @inheritdoc
670685
*/

0 commit comments

Comments
 (0)