I want to connect to a redis cluster through an HA. My config is like this:
snc_redis:
clients:
cluster_test_ha:
type: predis
alias: cluster_test_ha
dsn: "%redis_cluster_ha_address%"
options:
replication: false
cluster: 'redis'
connection_timeout: 10
read_write_timeout: 10
And I am using it like this:
$redisClient = $this->getContainer()->get('snc_redis.cluster_test_ha');
try {
$key="test125412";
$redisClient->set($key, 12);
} catch (\Throwable $e) {
dump($e->getMessage());
}
It is ok when I am connected to the node on which $key
will be persisted. But when redis sends a redirect to another node, it tries to connect to 127.0.0.1 instead of redis server ip, so i get this exception:
Connection refused [tcp://127.0.0.1:7002]
I am using snc_redis v 2.1.13
P.S: I tried with rediscli and it redirects right, so there seems to be no problem on redis side.
I found out that the problem is on redis side. Nodes knew other nodes on right ip address but knew themselves on 127.0.0.1. You may see that here (I masked the real ip address with redis server ip
label):
So I just connected to each node and make it meet
itself on the right ip asdress (not 127.0.0.1
). As you may see, after that it found itself on the right ip address and my problem solved.