Redis CLIENT SETNAME 命令

Redis 服务器

Redis CLIENT SETNAME 命令用于指定当前连接的名称。

这个名字会显示在 CLIENT LIST 命令的结果中, 用于识别当前正在与服务器进行连接的客户端。

 

1. 语法

redis CLIENT SETNAME 命令基本语法如下:

redis 127.0.0.1:6379> CLIENT SETNAME connection-name

 

2. 可用版本

>= 2.6.9

 

3. 返回值

设置成功时返回 OK 。

 

4. 范例

# 新连接默认没有名字

redis 127.0.0.1:6379> CLIENT GETNAME
(nil)

# 设置名字

redis 127.0.0.1:6379> CLIENT SETNAME hello-world-connection
OK

# 返回名字

redis 127.0.0.1:6379> CLIENT GETNAME
"hello-world-connection"

# 在客户端列表中查看

redis 127.0.0.1:6379> CLIENT LIST
addr=127.0.0.1:36851
fd=5
name=hello-world-connection     # <- 名字
age=51
...

# 清除名字

redis 127.0.0.1:6379> CLIENT SETNAME        # 只用空格是不行的!
(error) ERR Syntax error, try CLIENT (LIST | KILL ip:port)

redis 127.0.0.1:6379> CLIENT SETNAME ""     # 必须双引号显示包围
OK

redis 127.0.0.1:6379> CLIENT GETNAME        # 清除完毕
(nil)

Redis 服务器

Redis CLIENT SETNAME 命令

Redis 服务器

Redis CLIENT SETNAME 命令用于指定当前连接的名称。

这个名字会显示在 CLIENT LIST 命令的结果中, 用于识别当前正在与服务器进行连接的客户端。

 

1. 语法

redis CLIENT SETNAME 命令基本语法如下:

redis 127.0.0.1:6379> CLIENT SETNAME connection-name

 

2. 可用版本

>= 2.6.9

 

3. 返回值

设置成功时返回 OK 。

 

4. 范例

# 新连接默认没有名字

redis 127.0.0.1:6379> CLIENT GETNAME
(nil)

# 设置名字

redis 127.0.0.1:6379> CLIENT SETNAME hello-world-connection
OK

# 返回名字

redis 127.0.0.1:6379> CLIENT GETNAME
"hello-world-connection"

# 在客户端列表中查看

redis 127.0.0.1:6379> CLIENT LIST
addr=127.0.0.1:36851
fd=5
name=hello-world-connection     # <- 名字
age=51
...

# 清除名字

redis 127.0.0.1:6379> CLIENT SETNAME        # 只用空格是不行的!
(error) ERR Syntax error, try CLIENT (LIST | KILL ip:port)

redis 127.0.0.1:6379> CLIENT SETNAME ""     # 必须双引号显示包围
OK

redis 127.0.0.1:6379> CLIENT GETNAME        # 清除完毕
(nil)

Redis 服务器

Redis CLUSTER SLOTS 命令用于以数组形式展示集群的当前状态。redis CLUSTER SLOTS 命令基本语法如下:CLUSTER SLOTS。返回值:IP/端口嵌套的列表数组。