Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cluster_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,8 @@ void cluster_init_cache(redisCluster *c, redisCachedCluster *cc) {
c->flags->timeout, c->flags->read_timeout,
c->flags->persistent, NULL, 0);

/* Stream context */
/* Credentials and stream context */
redis_sock_set_auth(sock, c->flags->user, c->flags->pass);
redis_sock_set_context(sock, c->flags->context);

/* Add to seed nodes */
Expand Down
57 changes: 57 additions & 0 deletions tests/RedisClusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,63 @@ private function movedCount(array $nodes): int {
return $count;
}

public function testCachedSeedsAuthenticateDuringRemap() {
if (!$this->getAuth() || !$this->minVersionCheck('5.0'))
$this->markTestSkipped('Authentication and CLIENT ID are required');

$class = $this->getRedisClusterClass();
$key = '{cached-seed-auth}' . uniqid();
if (!($replicas = $this->replicasForKey($key)))
$this->markTestSkipped('A known replica is required for remapping');

$slot = $this->redis->cluster($key, 'KEYSLOT', $key);
foreach ($this->redis->rawCommand($key, 'CLUSTER', 'SLOTS') as $range) {
if ($slot >= $range[0] && $slot <= $range[1]) {
$node = $this->connectToNode([$range[2][0], $range[2][1]]);
break;
}
}
$endpoint = implode(':', $replicas[0]);
/* A MOVED to a known replica triggers the legacy full remap. The retry
* succeeds without changing the cluster's topology. */
$script = "local n = redis.call('INCR', KEYS[1]); " .
"if n == 1 then return redis.error_reply('MOVED $slot $endpoint') end; return n";
$cache = ini_get('redis.clusters.cache_slots');
$client = $populator = null;
$ids = [];

try {
foreach ([false, true] as $persistent) {
foreach ([0, 1] as $cached) {
ini_set('redis.clusters.cache_slots', $cached);
if ($cached) {
$populator = new $class(null, self::$seeds, 1, 1,
$persistent, $this->getAuth());
$populator->close();
$populator = null;
}
$client = new $class(null, self::$seeds, 1, 1,
$persistent, $this->getAuth());
$ids[] = $client->rawCommand($key, 'CLIENT', 'ID');
$client->del($key);
$this->assertEquals(2, $client->eval($script, [$key], 1));
$this->assertEquals('2', $client->get($key));
$this->assertEquals(Redis::ATOMIC, $client->getMode());
$client->close();
$client = null;
}
}
} finally {
if ($client) $client->close();
if ($populator) $populator->close();
$this->redis->del($key);
/* The existing remap connection leak is independent of this test. */
foreach ($ids as $id) $node->rawCommand('CLIENT', 'KILL', 'ID', $id);
$node->close();
ini_set('redis.clusters.cache_slots', $cache);
}
}

/* A replica that hangs up on us is reconnected transparently, but the
* READONLY we sent doesn't survive the new connection, so we have to send
* it again or the replica answers MOVED to every read we send it. */
Expand Down
Loading