Redis Client Setname Command
The Redis Client Setname command is used to specify the name of the current connection.
This name will be displayed in the results of the CLIENT LIST command, used to identify the client currently connected to the server.
Syntax
The basic syntax for the redis Client Setname command is as follows:
redis 127.0.0.1:6379> CLIENT SETNAME connection-name
Available Versions
= 2.6.9
Return Value
Returns OK if the setting is successful.
Example
# New connection has no name by default
redis 127.0.0.1:6379> CLIENT GETNAME
(nil)
# Set the name
redis 127.0.0.1:6379> CLIENT SETNAME hello-world-connection
OK
# Return the name
redis 127.0.0.1:6379> CLIENT GETNAME
"hello-world-connection"
# View in the client list
redis 127.0.0.1:6379> CLIENT LIST
addr=127.0.0.1:36851
fd=5
name=hello-world-connection # <- The name
age=51
...
# Clear the name
redis 127.0.0.1:6379> CLIENT SETNAME # Spaces alone are not allowed!
(error) ERR Syntax error, try CLIENT (LIST | KILL ip:port)
redis 127.0.0.1:6379> CLIENT SETNAME "" # Must be enclosed in double quotes
OK
redis 127.0.0.1:6379> CLIENT GETNAME # Cleared successfully
(nil)