predis: Connection scheme (rediss) seems to be ignored when retrieving (new) clients from the IteratorAggregate
Describe the bug Predis/Client configured in cluster mode does not behave correctly when using the iterator to get individual node connections. The scheme used when configuring the cluster wide client, seems to be forgotten when a node connection is requested. Eg: When rediss (aka TLS over TCP) is requested a node connection will fall back to just using TCP.
Reason for using the iterator: KEYS/SCAN operator seems to be undefined when using the cluster mode, thus we assume it would be possible to iterate over all the nodes, and issue a KEYS/SCAN operation on them.
Background MemoryDB for redis seems to be an Amazon specific, but Redis protocol compliant implementation of Redis. The setup we have is a single shard, multiple replica Redis cluster.
Expected behavior A. Be able to successfully issue a KEYS/SCAN command when running in (p)redis-cluster mode or B. When creating new connections using the Client iterator, use the scheme provided in the original config.
Versions (please complete the following information):
- Predis: 2.1.2
- PHP: 7.3
- Redis: Amazon MemoryDB for Redis
- OS: Ubuntu Bionic (docker image “ubuntu@sha256:c1d0baf2425ecef88a2f0c3543ec43690dc16cc80d3c4e593bb95e4f45390e45”)
Code sample
Dependency injection:
class: Predis\Client
arguments:
$parameters:
- { scheme: '%redis_shared.scheme%', host: '%redis_shared.host%', port: '%redis_shared.port%', username: '%redis_shared.username%', password: '%redis_shared.password%' }
$options: { prefix: '%redis.database.geo_prefix%', cluster: 'redis' }
where redis_shared.scheme
= “rediss” and the redis_shared.host
is of following format: clustercfg.<project-name>-eu-central-1.htpkhd.memorydb.eu-central-1.amazonaws.com
. More specifically, this DNS record resolves to the 3 replica IP’s.
$contexts = [];
$pattern = '<pattern>.*';
foreach ($this->redisClient as $nodeClient)
{
foreach (new Iterator\Keyspace($nodeClient, $pattern) as $key)
{
list(/*prefix*/, $context) = explode('.', $key, 2);
$contexts[] = $context;
}
}
return $contexts;
$this->redisClient
is the cluster configured Predis/Client, $nodeClient
is, what I assume a client that is able to issue commands to a single instance
Result stacktrace:
In AbstractConnection.php line 131: │
│ │
│ [Predis\Connection\ConnectionException] │
│ Error while reading line from the server. [tcp://<node-uri>-aws-eu-central-1.htpkhd.memorydb.eu-central-1.amazonaws.com:6379]
Additional context Other actions such as SET or append to list are working when using the cluster client.
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 18 (9 by maintainers)
I’m gonna have to reopen this issue as it seems like other programming languages seem to consider memorydb as a cluster implementation.
https://github.com/abhirockzz/memorydb-cloud9-quickstart/blob/master/main.go https://github.com/aws-samples/amazon-memorydb-for-redis-java-client-examples/blob/main/src/com/amazonaws/amazonmemorydbdemo/RedisMemoryDBDemo.java#L141
I have yet to further progress into attempting this in PHP, with Predis. With Kubecon last week and currently attempting a switch to PHPRedis (which is going less than ok), I’ve yet to return to a cluster setup.