Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis Cluster: Find which master holds particular key/slot

Tags:

redis

lua

I'm using Redis Cluster, and some keys have a special prefix {foo}, so redis puts them in one slot.

I do this because i want to run some lua scripts against these keys (i can do this if i login to the master as a single instance).

In my setup i have 3 masters, but not sure how to find master which holds slot with my keys {foo}.*

Do you know any way to find master which holds particular key/slot?

like image 334
TermiT Avatar asked Jun 01 '15 20:06

TermiT


Video Answer


1 Answers

I still have to read the entire docs, but already found this:

There are 16384 hash slots in Redis Cluster, and to compute what is the hash slot of a given key, we simply take the CRC16 of the key modulo 16384.

There is a command for that op already:

http://redis.io/commands/cluster-keyslot

>CLUSTER KEYSLOT somekey
11058

And to find which slots are there in a server:

http://redis.io/commands/cluster-slots

like image 84
Niloct Avatar answered Sep 22 '22 20:09

Niloct