Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Client Setname Command

Redis Client Setname Command

Redis Server

The Redis Client Setname command is used to set the name of the current connection.

This name is displayed in CLIENT LIST the result of the command, 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 on success.

Example



# New connections default to having no name



redis 127.0.0.1:6379> CLIENT GETNAME

(nil)



# Set name



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

OK



# Return name



redis 127.0.0.1:6379> CLIENT GETNAME

"hello-world-connection"



# View in client list



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 Server