How to switch nodes easily in a redis cluster cli?
I have a three node redis cluster.
If I run cluster nodes
after I connect to one of the node via redis-cli
, I got this output:
10.0.32.70:6379> cluster nodes
fedd7d9220ca59045782050e9c418103fdeee3bf 10.0.33.13:6379@1122 slave 56ada5e1cc30ba1889950df4c4203b856wc83558 0 1595241803685 2 connected
9eac3667c13055555555a52b20628da372dadc21 10.0.32.161:6379@1122 slave 81777bc32d3ff82da733e4b8f36a14e8de25e057 0 1595241801000 1 connected
861e7ed26924bcccccccaa23b1977982397000e7 10.0.33.231:6379@1122 slave 10397e832212231dc40ec687798f245a39007506 0 1595241802678 3 connected
10397e832212231dc40ec687798f245a39007506 10.0.32.117:6379@1122 master - 0 1595241801671 3 connected 10923-16383
81777bc32d3ff82da733e4b8f36a14e8de25e057 10.0.33.11:6379@1122 master - 0 1595241802000 1 connected 5462-10922
56ada5e1cc30ba1889950df4c4203b856wc83558 10.0.32.70:6379@1122 myself,master - 0 1595241801000 2 connected 0-5461
Now I want to switch to a different node from the current node.
When I use select
, I got the following error:
> select 1
(error) ERR SELECT is not allowed in cluster mode
I can trigger a switch by using get 1
, get 2
... etc (Basically a get command with a random integer). A few trial and error will land me on the right node.
Is there an easier way?
you can try get <id of the node>. In your case.
get 10397e832212231dc40ec687798f245a39007506
get 81777bc32d3ff82da733e4b8f36a14e8de25e057
get 56ada5e1cc30ba1889950df4c4203b856wc83558
You can only connect to master nodes using get . If you try connecting to slave using get. It will connect to master node only.