resty-redis-cluster icon indicating copy to clipboard operation
resty-redis-cluster copied to clipboard

Construct slot_ cache exception

Open pzhx521 opened this issue 2 years ago • 0 comments

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.

pzhx521 avatar Feb 21 '23 04:02 pzhx521