Help & Documentation>Tencent Cloud Distributed Cache

Use Cases of Custom Commands

Last updated: 2024-02-26 17:47:01

The Memory Edition (Cluster Architecture) encapsulates VIP, providing the user experience of a standalone version under cluster mode, bringing immense convenience to business operations. In operational scenarios, there may be a frequent need to access each node in the cluster to locate anomalies. A custom command adds a parameter, "Node ID", based on the existing command parameter list. The command format is COMMAND arg1 arg2 ... [Node ID], facilitating the retrieval of information from a specified node. Node ID information can be obtained from the Redis Console on the Node Management page, or through the cluster nodes command.

Release notes

In proxy agent versions prior to v5.5.0, the node ID is required for the execution of customized commands, but it is not required in v5.5.0 and later.

INFO

This command returns the information and statistics of a server.

Custom command format

info [section] [node ID]
Here, optional parameters can be used to select a specific part of the information:
server: The general information about the Redis server
clients: The information of connected clients
memory: The information of memory usage.
persistence: The information of RDB and AOF
stats: General statistical data
replication: The information of master/replica replication
cpu: The information of CPU usage
commandstats: The statistics of Redis commands
cluster: The information of a Redis cluster
keyspace: Database-related statistics
Optional parameters can also take the following values:
all: Returns all the information.
default: Returns the default information.
For details, see INFO Command.

Sample Code

The following example runs the INFO command with section being server:


SLOWLOG

To read slow logs, use the SLOWLOG GET command, which returns each entry in the slow logs. You can choose to return only the N most recent entries and pass other parameters to the command (e.g., SLOWLOG GET 10).

Custom command format

slowlog get [Redis node ID]
slowlog get [slow log quantity][Redis node ID]

Sample Code





FLUSHDB

This command deletes all keys of the currently selected database. It will never fail.

Custom command format

flushdb [Redis node ID]

Sample Code

cd-crs-rhxxxay.sql.tencentcdb.com:24894> flushdb f2f3c387b9fab0e67af02039845c60278b13bed0
OK

PING

This command is often used to test whether the connection still exists or to measure the latency.

Custom command format

ping [message] [node ID]

Sample Code

[ crs-rh** | DB0 ] # PING "PONG" f2f3c3******
PONG
[ crs-rh** | DB0 ] # PING "hello world"
hello world

KEYS

This command queries all the matched keys.

Custom command format

keys [pattern] [Redis Node ID]

Sample Code

keys a* f2f3c3*****




SCAN

Custom command format

scan cursor [MATCH pattern] [COUNT count] [Redis node ID]

Sample Code

[ crs-** | DB0 ] # scan 0 f2f3c3*****
1) "2"

IMonitor

Execute the command on the Proxy node, with the parameter being the node ID of Redis shard, as shown below.
imonitor [Redis Node ID]
Sample Code
imonitor 3dba154c67925520ef1a1e2c41d8cc22d7f4**
+OK
+1680504260.729707 [0 127.0.0.1:6379] "auth" **
+1680504260.730070 [0 127.0.0.1:6379] "info" "commandstats"
+1680504262.243004 [0 127.0.0.1:6379] "AUTH" **