phpredis / phpredis

A PHP extension for Redis
Other
9.98k stars 2.14k forks source link

Couldn't map cluster keyspace using any provided seed #1533

Closed Thomas-1985 closed 4 years ago

Thomas-1985 commented 5 years ago

Expected behaviour

Actual behaviour

I'm seeing this behaviour on

Steps to reproduce, backtrace or example script

redis-cli -p 13000 -a cluster nodes -> shows all nodes

I've checked

Cheers Thomy

yatsukhnenko commented 5 years ago

Duplicate #1532

michael-grunder commented 5 years ago

Hi @Thomas-1985, the two issues may be unrelated. We just randomly got two very similar issues in rapid succession.

These seem to relate to different versions of phpRedis, Redis, and PHP itself.

I've never used Nextcloud, but are you able to connect to the cluster via redis-cli?

Update: I just noticed you said you can connect via redis-cli. In that case, are you able to connect to a specific node using PhpRedis (not the cluster class)?

Thomas-1985 commented 5 years ago

Yes i wrote that in the initial thread:

redis-cli -p 13000 -a cluster nodes -> shows all nodes

michael-grunder commented 5 years ago

What I want to know is if you are able to use phpredis to connect to a single node:

e.g.:

$obj_r = new Redis();
$obj_r->connect(ip_address, 13000);
var_dump($obj_r->ping());

We know phpredis can connect to Redis cluster since thousands of people are using to do so, so the issue is trying to figure out what specific issue you are having.

Thomas-1985 commented 5 years ago

Hi

This is possible (i run 6 nodes and tested towards 2 of them)

root@nc-wb1:~# php test-redis.php string(5) "+PONG"

This is tested against ii php-redis 4.2.0-1+ubuntu16.04.1+deb.sury.org+1 amd64 PHP extension for interfacing with Redis

Please help me how to test if it works for a cluster also

michael-grunder commented 5 years ago

Hey,

To test your cluster you could first make sure it's working and in cluster mode, by doing something like this:

$ redis-cli -h localhost -c -p 7000 cluster info|grep state
cluster_state:ok

You'll need to change the host and port to the ones you're using and want to make sure that it says cluster_state:ok to make sure you're running in cluster mode.

Edit:

Then, you can try running redis-cli in cluster mode and make sure you can set keys and are being redirected without errors:

$ redis-cli -c -h <host> -p <port>
Thomas-1985 commented 5 years ago

root@nc-rc1:~# redis-cli -c -h 192.168.150.70 -p 13000 -a ... cluster info Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 cluster_size:3 cluster_current_epoch:6 cluster_my_epoch:1 cluster_stats_messages_ping_sent:4670411 cluster_stats_messages_pong_sent:4574970 cluster_stats_messages_sent:9245381 cluster_stats_messages_ping_received:4574965 cluster_stats_messages_pong_received:4670368 cluster_stats_messages_meet_received:5 cluster_stats_messages_fail_received:2 cluster_stats_messages_received:9245340

huguesalary commented 5 years ago

I'm having the same issue. On my end, however, when running the "CLUSTER SLOTS" command (which is what phpredis is doing when this bug happens), I receive a dubious output from Redis, which makes me think the issue is, indeed, with the state of my redis cluster:

127.0.0.1:6379> CLUSTER SLOTS

  1) 1) (integer) 0
   2) (integer) 5460
   3) 1) ""
      2) (integer) 0
      3) "db641896e4e0b4995f623fd6accf222bc468d91c"
   4) 1) ""
      2) (integer) 0
      3) "632ec282915125d9df0ac18ea6afbd37da44b33f"
2) 1) (integer) 10923
   2) (integer) 16383
   3) 1) ""
      2) (integer) 0
      3) "89520140f5254842c2c7662373a4fa3b0567db8e"
   4) 1) ""
      2) (integer) 0
      3) "3c0cc4d762b61bf7d541a31aa938c52337c42753"
3) 1) (integer) 5461
   2) (integer) 10922
   3) 1) ""
      2) (integer) 0
      3) "10c615143d24d3941dfe8bbb6e936455313a7421"
   4) 1) "172.17.0.24"
      2) (integer) 6379
      3) "f3fc6db8c825f6149214f39b17cd3ed60de4c00e"
michael-grunder commented 5 years ago

@Thomas-1985 Are you still having this issue?

Thomas-1985 commented 5 years ago

Hi

Unfortunately yes

michael-grunder commented 5 years ago

I'm not sure how I can help, but if you pasted the output from CLUSTER SLOTS that could provide a hint. Another thing you could try is testing the cluster without a password.

Other than that, you could see if another library can connect to your cluster (e.g. Predis) to confirm the cluster is set up correctly.

furester commented 5 years ago

@Thomas-1985 if you are connecting to a cluster of Redis you could use

$hosts = [$host . ':' . $port];
$obj_r = new RedisCluster(null, $hosts);

(you have to concat $host and $port params of your connection and put them in an array). while with plain Redis you use:

$obj_r = new Redis();
$obj_r->pconnect($host, $port, $timeout);

there is also a RedisArray class if you have an other 'cluster' configuration.

If you need some code samples you could find it here: furester/silex-php-redis

michael-grunder commented 5 years ago

I wrote a small utility script that may be helpful in diagnosing the issue you're having.

It's going to be hard to find a solution without more information.

kojima-akira-sz commented 5 years ago

Hi, I had the same problem.

It works normally, but this problem occurs under high load environment.

OS: Docker image: php:7.2-fpm(on AWS ECS FARGATE) Redis: 5.0.4 (AWS ElastiCache) PHP: 7.2.21 phpredis: 5.0.2

I try utility script.

Results:

Checking general cluster INFO: OK
Checking [6923:7946] (172.18.51.132:6379): OK
Checking [6923:7946] (172.18.52.60:6379): OK
Checking [2048:2652] (172.18.52.20:6379): OK
Checking [2048:2652] (172.18.50.248:6379): OK
Checking [6749:6922] (172.18.52.20:6379): OK
Checking [6749:6922] (172.18.50.248:6379): OK
Checking [7947:8191] (172.18.52.20:6379): OK
Checking [7947:8191] (172.18.50.248:6379): OK
Checking [6713:6748] (172.18.51.235:6379): OK
Checking [6713:6748] (172.18.50.182:6379): OK
Checking [8192:9179] (172.18.51.235:6379): OK
Checking [8192:9179] (172.18.50.182:6379): OK
Checking [6050:6712] (172.18.52.18:6379): OK
Checking [6050:6712] (172.18.51.79:6379): OK
Checking [9180:9540] (172.18.52.18:6379): OK
Checking [9180:9540] (172.18.51.79:6379): OK
Checking [3424:4447] (172.18.51.45:6379): OK
Checking [3424:4447] (172.18.50.55:6379): OK
Checking [10154:10832] (172.18.52.32:6379): OK
Checking [10154:10832] (172.18.51.24:6379): OK
Checking [11857:12201] (172.18.52.32:6379): OK
Checking [11857:12201] (172.18.51.24:6379): OK
Checking [14440:15463] (172.18.50.30:6379): OK
Checking [14440:15463] (172.18.51.17:6379): OK
Checking [564:1587] (172.18.52.145:6379): OK
Checking [564:1587] (172.18.51.230:6379): OK
Checking [5484:6049] (172.18.51.226:6379): OK
Checking [5484:6049] (172.18.50.92:6379): OK
Checking [9541:9657] (172.18.51.226:6379): OK
Checking [9541:9657] (172.18.50.92:6379): OK
Checking [13754:14094] (172.18.51.226:6379): OK
Checking [13754:14094] (172.18.50.92:6379): OK
Checking [10833:11856] (172.18.50.98:6379): OK
Checking [10833:11856] (172.18.52.79:6379): OK
Checking [0:563] (172.18.50.115:6379): OK
Checking [0:563] (172.18.52.53:6379): OK
Checking [1588:2047] (172.18.50.115:6379): OK
Checking [1588:2047] (172.18.52.53:6379): OK
Checking [2653:3423] (172.18.50.134:6379): OK
Checking [2653:3423] (172.18.51.61:6379): OK
Checking [4448:4459] (172.18.50.134:6379): OK
Checking [4448:4459] (172.18.51.61:6379): OK
Checking [14095:14335] (172.18.50.134:6379): OK
Checking [14095:14335] (172.18.51.61:6379): OK
Checking [14336:14439] (172.18.50.10:6379): OK
Checking [14336:14439] (172.18.52.244:6379): OK
Checking [15464:16383] (172.18.50.10:6379): OK
Checking [15464:16383] (172.18.52.244:6379): OK
Checking [12730:13753] (172.18.51.162:6379): OK
Checking [12730:13753] (172.18.50.172:6379): OK
Checking [4460:5483] (172.18.52.163:6379): OK
Checking [4460:5483] (172.18.51.246:6379): OK
Checking [9658:10153] (172.18.52.26:6379): OK
Checking [9658:10153] (172.18.51.233:6379): OK
Checking [12202:12729] (172.18.52.26:6379): OK
Checking [12202:12729] (172.18.51.233:6379): OK
Attempting to set key 'phpredis-cluster-key:0'
Redirected to '172.18.51.45:6379'
Success setting 'phpredis-cluster-key:0'
Attempting to set key 'phpredis-cluster-key:1'
Redirected to '172.18.50.115:6379'
Success setting 'phpredis-cluster-key:1'
Attempting to set key 'phpredis-cluster-key:2'
Redirected to '172.18.52.26:6379'
Success setting 'phpredis-cluster-key:2'
Attempting to set key 'phpredis-cluster-key:3'
Redirected to '172.18.51.235:6379'
Success setting 'phpredis-cluster-key:3'
Attempting to set key 'phpredis-cluster-key:4'
Redirected to '172.18.51.45:6379'
Redirected to '172.18.50.115:6379'
Success setting 'phpredis-cluster-key:4'
Attempting to set key 'phpredis-cluster-key:5'
Redirected to '172.18.52.26:6379'
Success setting 'phpredis-cluster-key:5'
Attempting to set key 'phpredis-cluster-key:6'
Redirected to '172.18.51.235:6379'
Success setting 'phpredis-cluster-key:6'
Attempting to set key 'phpredis-cluster-key:7'
Redirected to '172.18.51.45:6379'
Success setting 'phpredis-cluster-key:7'
Attempting to set key 'phpredis-cluster-key:8'
Redirected to '172.18.52.163:6379'
Success setting 'phpredis-cluster-key:8'
Attempting to set key 'phpredis-cluster-key:9'
Redirected to '172.18.50.115:6379'
Redirected to '172.18.52.26:6379'
Success setting 'phpredis-cluster-key:9'
Cluster seems OK
kojima-akira-sz commented 5 years ago

In AWS ElastiCache, using "node endpoint" instead of "configuration endpoint" reduced the number of errors.

https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Endpoints.html

kojima-akira-sz commented 5 years ago

Hi, It was solved in my environment. The cause was the library version.

I misunderstood the installed version. I'm so sory.

michael-grunder commented 4 years ago

Closing this issue since there is no activity in a while. If you are still having problems connecting feel free to reopen.

ebogdanov commented 3 years ago

Met same problem. This error actually means either:

  1. Client can't connect to cluster (timeouts)
  2. Instance is not in cluster mode
  3. Client connected successfully, but auth failed. Let's say cluster have password specified in config, but you're trying yo connect with client which do not sends password.
Patrick-Remy commented 2 years ago

Also met this – imho a failed authentication should throw a specific exception/error, not this general error.

InfraBackend commented 2 years ago
image

Adding password to option can solve my problem.

dealer-solutions-gene commented 2 years ago

I ran into this issue when I had an AWS Cluster with a single shard, increasing this to two shards solved my problem

PHP 5.6 / PHP Redis 2.2.8

anabeto93 commented 6 months ago
image

Adding password to option can solve my problem.

This right here is the answer and yet I didn't see this in the laravel docs