Redis 简明教程

Redis - Commands

Redis 命令用于对 Redis 服务器执行一些操作。

Redis commands are used to perform some operations on Redis server.

要在 Redis 服务器上运行命令,您需要一个 Redis 客户端。Redis 软件包中提供 Redis 客户端,我们已经安装过了。

To run commands on Redis server, you need a Redis client. Redis client is available in Redis package, which we have installed earlier.

Syntax

以下是 Redis 客户端的基本语法。

Following is the basic syntax of Redis client.

$redis-cli

Example

下面的示例说明如何启动 Redis 客户端。

Following example explains how we can start Redis client.

要启动 Redis 客户端,请打开终端并键入命令 redis-cli 。然后将连接到本地服务器。然后可以运行任何命令。

To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command.

$redis-cli
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> PING
PONG

在上面的示例中,我们连接到在本地计算机上运行的 Redis 服务器,并执行了一个命令 PING ,可以检查服务器是否在运行。

In the above example, we connect to Redis server running on the local machine and execute a command PING, that checks whether the server is running or not.

Run Commands on the Remote Server

要运行 Redis 远程服务器上的命令,您需要通过相同的客户端 redis-cli 连接到服务器

To run commands on Redis remote server, you need to connect to the server by the same client redis-cli

Syntax

$ redis-cli -h host -p port -a password

Example

下面的示例显示如何连接到 Redis 远程服务器,该服务器在主机 127.0.0.1 上运行,端口为 6379,密码为 mypass。

Following example shows how to connect to Redis remote server, running on host 127.0.0.1, port 6379 and has 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