steve0511 / resty-redis-cluster

Openresty lua client for redis cluster.
Apache License 2.0
376 stars 134 forks source link

Construct slot_ cache exception #105

Open pzhx521 opened 1 year ago

pzhx521 commented 1 year ago

https://github.com/steve0511/resty-redis-cluster/blob/e080402bb29f7ab0d00dd81f1bdfb43037bd204a/lib/resty/rediscluster.lua#L142

Hello, when the slot is retrieved, the Redis cluster slots command returns a null value, for example:

I have no name!@redis-cluster-2:/$ redis-cli -c
127.0.0.1:6379> CLUSTER SLOTS
1) 1) (integer) 0
   2) (integer) 5460
   3) 1) ""
      2) (integer) 0
   4) 1) "192.168.43.9"
      2) (integer) 6379
2) 1) (integer) 5461
   2) (integer) 10922
   3) 1) "192.168.47.120"
      2) (integer) 6379
   4) 1) "192.168.41.44"
      2) (integer) 6379
3) 1) (integer) 10923
   2) (integer) 16383
   3) 1) "192.168.58.183"
      2) (integer) 6379
   4) 1) "192.168.36.214"
      2) (integer) 6379

It can be found that the primary node IP in the first group of slots is empty. (The next time you execute this command, you find that the data is normal, not the Redis cluster problem)

The description of this part in the Redis document is as follows. redis cluster-slots image

However, it is found that there is no non-empty judgment in our source code, resulting in incorrect updated slot information.When the next access hits the slot, the following error message will be generated:

pipeline commit failed while connecting to  :0

The IP information of slot is lost.

I think it is necessary to add non-empty judgment to expose error information in advance.

                    ...
                    -- generate new list of servers
                    if sub_info[3][1] == nil or #sub_info[3][1] <= 0 then
                        return nil, "failed to fetch slots, slots_info[".. n .."] config is empty"
                    end
                   ...

We look forward to your reply.