English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Der Redis Client Setname-Befehl

Redis Server

Der Redis Client Setname-Befehl wird verwendet, um den Namen der aktuellen Verbindung zu spezifizieren.

This name will be displayed in  CLIENT LIST   In the command result, it is used to identify the client currently connected to the server.

Syntax

The basic syntax of the redis Client Setname command is as follows:

redis 127.0.0.1:6379> CLIENT SETNAME connection-name

Available Version

>= 2.6.9

Return Value

Returns OK when set successfully.

Online Example

# 新连接默认没有名字
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     # <- Name
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 Server