predis: Unable to connect to TLS Elasticcache cluster without specifying all nodes in cluster
Hello,
I am having issues using Predis to connect to an Elasticcache cluster, unless I specify all nodes in the cluster in this way:
$cluster = [
'tls://tls-cluster-node-001:6379',
'tls://tls-cluster-node-002:6379',
'tls://tls-cluster-node-003:6379'
];
$client = new \Predis\Client($cluster, ['scheme' => 'tls', 'cluster' => 'redis']
If I list the cluster configuration endpoint from AWS (using tls URI scheme) as the only endpoint, I get the following error:
PHP Fatal error: Uncaught exception 'Predis\ClientException' with message 'No connections available in the pool' in /opt/php/php-5.6.8/share/pear/Predis/Connection/Aggregate/RedisCluster.php:337
Additionally, if I only list one node in the cluster (with the tls URI scheme), Predis will attempt to connect to the other nodes it discovers using the tcp URI scheme (which causes it to fail):
PHP Fatal error: Uncaught exception 'Predis\Connection\ConnectionException' with message 'Error while reading line from the server. [tcp://<node-instance>.cache.amazonaws.com:6379]' in /opt/php/php-5.6.8/share/pear/Predis/Connection/AbstractConnection.php:155
Ideally, I would not like to deal with individual nodes and would rather put a DNS entry over the cluster configuration endpoint and only specify that to Predis. This seems like a bug. If it’s not, would someone be able to advise me on what is wrong with the setup? Thanks.
Here’s my info:
- php version: 5.6.8
- Elasticcache redis driver version: 3.2.6
- Predis version: 1.1.1
- OS: ubuntu 14.04
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (1 by maintainers)
Commits related to this issue
- accept top level redis cluster config the current code only accepts the top level config to be of type 'default' or requires that there be a 'clusters' array like so 'client' => 'predis', 'c... — committed to totersapp/framework by abbood 5 years ago
- accept top level redis cluster config the current code only accepts the top level config to be of type 'default' or requires that there be a 'clusters' array like so 'client' => 'predis', 'c... — committed to totersapp/framework by abbood 5 years ago
- accept top level redis cluster config the current code only accepts the top level config to be of type 'default' or requires that there be a 'clusters' array like so 'client' => 'predis', 'c... — committed to totersapp/framework by abbood 5 years ago
- accept top level redis cluster config the current code only accepts the top level config to be of type 'default' or requires that there be a 'clusters' array like so 'client' => 'predis', 'c... — committed to totersapp/framework by abbood 5 years ago
I had a similar issue in configuring this.
If you look carefully at the ‘Error while reading line from the server’, you’ll notice that it fell back to
tcp
. This happened when the node sent a-MOVE
(redirect) back to your client.The solution is to your issue can be accomplished by specifying ‘parameters’ in your
options
that are passed in. Parameters set the ‘defaults’ for the Connection Factory, which is then used when one cluster node informs you to redirect to another node.I’m using Laravel with Redis, but this configuration is passed through straight to Predis, and it should work for you with minor changes:
Also note that it will roll through the various connections, so perform tests at least twice to prove against false positives (hitting the correct cluster node on luck, and not experiencing a redirect).