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

Redis Client Setname command

Redis Server

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

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 Examples

# New connections are not named by default
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     # <- Name
age=51
...
# Clearing name
redis 127.0.0.1:6379> CLIENT SETNAME        # Only spaces are not enough!
(error) ERR Syntax error, try CLIENT (LIST | KILL ip:port)
redis 127.0.0.1:6379> CLIENT SETNAME ""     # Must be enclosed with double quotes!
OK
redis 127.0.0.1:6379> CLIENT GETNAME        # Clearing completed
(nil)

Redis Server