Redis 简明教程

Redis - Client Connection

如果启用,Redis 接受在已配置监听 TCP 端口和 Unix 套接字上的客户端连接。接受新的客户端连接时,将执行以下操作:

Redis accepts clients’ connections on the configured listening TCP port and on the Unix socket, if enabled. When a new client connection is accepted, the following operations are performed −

  1. The client socket is put in non-blocking state since Redis uses multiplexing and non-blocking I/O.

  2. The TCP_NODELAY option is set in order to ensure that we don’t have delays in our connection.

  3. A readable file event is created so that Redis is able to collect the client queries as soon as new data is available to be read on the socket.

Maximum Number of Clients

在 Redis 配置(redis.conf)中,有一个名为 maxclients 的属性,该属性描述了可以连接到 Redis 的最大客户端数。

In Redis config (redis.conf), there is a property called maxclients, which describes the maximum number of clients that can connect to Redis.

以下是命令的基本句法。

Following is the basic syntax of command.

config get maxclients

1) "maxclients"
2) "10000"

默认情况下,此属性设置为 10000(取决于操作系统的最大文件描述符数量限制),但您可以更改此属性。

By default, this property is set to 10000 (depending upon the maximum number of file descriptors limit of OS), although you can change this property.

Example

在下面的示例中,我们在启动服务器时将最大客户端数量设为 100000。

In the following example, we have set the maximum number of clients to 100000, while starting the server.

redis-server --maxclients 100000

Client Commands

Sr.No

Command

Description

1

CLIENT LIST

Returns the list of clients connected to Redis server

2

CLIENT SETNAME

Assigns a name to the current connection

3

CLIENT GETNAME

Returns the name of the current connection as set by CLIENT SETNAME

4

CLIENT PAUSE

This is a connections control command able to suspend all the Redis clients for the specified amount of time (in milliseconds)

5

CLIENT KILL

This command closes a given client connection.