All Products
Search
Document Center

Tair (Redis® OSS-Compatible):Query the data node and slot to which a key belongs

Last Updated:Oct 24, 2024

Limits are imposed on the use of specific commands in Tair and Tair cluster instances. A single command cannot be run on keys that span multiple slots. Before you run a command on a key, you can use the CLUSTER KEYSLOT command to query the slot of the key to prevent errors from occurring during the command execution.

Procedure

  1. Connect to a Tair or Tair instance. For example, connect to a Redis instance by using redis-cli. For more information, see Use redis-cli to connect to an ApsaraDB for Redis instance.

  2. Run the following command to query the slot of a key:

    CLUSTER KEYSLOT <Key>

    For example, if you run the CLUSTER KEYSLOT foo command, the following result is expected to be returned:

    12182
  3. If your instance is a cluster instance in proxy mode, you can run the INFO KEY command to query the data node and slot to which a key belongs.

    INFO KEY <Key>

    For example, if you run the INFO KEY foo command, the following result is expected to be returned:

    slot:12182 node_index:2

References

The INFO KEY command is developed in-house by the Alibaba Cloud Tair team and is supported only for cluster instances in proxy mode. For more information, see In-house commands for ApsaraDB for Redis instances in proxy mode.

Cluster instances in proxy mode also allow you to run commands such as DEL and EXISTS on multiple keys across different slots. For more information, see Limits on commands supported by cluster instances and read/write splitting instances.