CLUSTER GETKEYSINSLOT
Since 1.1.0Cluster
Syntax
CLUSTER GETKEYSINSLOT slot countReturns up to count of the keys this node holds in slot. Tools that move slots between masters use it to find the keys to send with MIGRATE: redis-cli --cluster reshard asks for a batch, moves it, and asks again until the slot is empty. CLUSTER COUNTKEYSINSLOT counts them.
slot: a slot number from0to16383.count: the most keys to return,0or more.
The keys come in no particular order. Like CLUSTER COUNTKEYSINSLOT, it looks at this node's memory only, and walks every key of the node until it has count of them, so on a node with many keys it is slow; see the known issue in Adding a master and moving slots. On a server that is not a cluster node it replies ERR This instance has cluster support disabled, as Redis does.
A count of 0 returns an empty array, as in Redis. Both are since 1.2.1: 1.2.0 also worked on a server that was not a cluster node, and returned one key for a count of 0.
Reply
An array of key names; an empty array if the node holds none in the slot.
Errors
ERR Invalid slot n, must be between 0 and 16383.ERR Invalid slot or number of keys:countis negative.ERR value is not an integer or out of range:slotorcountis not a number.ERR This instance has cluster support disabled: the server is not a cluster node.
Examples
> MSET user:7 v {user:7}:cart 3 {user:7}:orders 7
OK
> CLUSTER GETKEYSINSLOT 2780 10
1) "user:7"
2) "{user:7}:cart"
3) "{user:7}:orders"
> CLUSTER GETKEYSINSLOT 2780 2
1) "user:7"
2) "{user:7}:cart"
> CLUSTER GETKEYSINSLOT 0 10
(empty array)