Redis command
Redis commands are used to perform operations on the redis service.
To execute commands on the redis service, a redis client is required. The Redis client is in the redis installation package we downloaded before.
Syntax
The basic syntax of the Redis client is:
$ redis-cli
Example
The following example explains how to start the redis client:
Start the redis client, open the terminal and enter the command redis-cli. This command will connect to the local redis service.
$redis-cli redis 127.0.0.1:6379> redis 127.0.0.1:6379> PING PONG
In the above example, we connect to the local redis service and execute the PING command, which is used to detect whether the redis service is started.
Execute commands on the remote service
If you need to execute commands on the remote redis service, we also use the redis-cli command.
Syntax
$ redis-cli -h host -p port -a password
Example
The following example demonstrates how to connect to the redis service with host 127.0.0.1, port 6379, and password mypass.
$redis-cli -h 127.0.0.1 -p 6379 -a "mypass" redis 127.0.0.1:6379> redis 127.0.0.1:6379> PING PONG