Redis Client Setname 命令

Redis 伺服器

Redis Client Setname 命令用於指定當前連接的名稱。

這個名字會顯示在 CLIENT LIST 命令的結果中, 用於識別當前正在與伺服器進行連接的客戶端。

語法

redis Client Setname 命令基本語法如下:

redis 127.0.0.1:6379> CLIENT SETNAME connection-name

可用版本

>= 2.6.9

返回值

設置成功時返回 OK 。

實例

# 新連接默認沒有名字

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 伺服器