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:> cluster nodes
fedd7d9220ca59045782050e9c418103fdeee3bf slave 56ada5e1cc30ba1889950df4c4203b856wc83558 0 1595241803685 2 connected
9eac3667c13055555555a52b20628da372dadc21 slave 81777bc32d3ff82da733e4b8f36a14e8de25e057 0 1595241801000 1 connected
861e7ed26924bcccccccaa23b1977982397000e7 slave 10397e832212231dc40ec687798f245a39007506 0 1595241802678 3 connected
10397e832212231dc40ec687798f245a39007506 master - 0 1595241801671 3 connected 10923-16383
81777bc32d3ff82da733e4b8f36a14e8de25e057 master - 0 1595241802000 1 connected 5462-10922
56ada5e1cc30ba1889950df4c4203b856wc83558 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.


From inside redis-cli, you can also go:

connect 6379

Or on my test cluster

connect localhost 30002

A possibly useful trick: On my test cluster (via create-cluster command, 3-node, default mapping), by trial and error, I found 3 short keys which are faster to type to switch nodes:

get 3  (node 1)
get 1  (node 2)
get 4  (node 3)

(3.14, like PI)

You have to first run redis-cli with the -c option to auto-switch nodes when you set/get a key.

If your cluster-mapping is different, you can just start using get to find short somehow-memorable ones that work on your cluster. Obviously the cluster mapping can change in the future so you would not want to use this in any permanent scripts/code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.