HELLO
Introduction and Use Case(s)
The HELLO command in Redis is used to initiate connections with specific protocol versions or to switch between different protocol versions during an active connection. It is particularly useful for clients that need to ensure they are communicating using a specific protocol version, typically RESP2 or RESP3.
Syntax
HELLO [protover [AUTH username password] [SETNAME clientname]]
Parameter Explanations
protover: Specifies the protocol version (e.g., 2 for RESP2 or 3 for RESP3).AUTH username password: Optionally provide credentials if authentication is required. Bothusernameandpasswordmust be supplied.SETNAME clientname: Optionally set the name of the client connection.
Return Values
The HELLO command returns information about the server in a nested array format, including details such as the protocol version, server ID, and available modules.
Example outputs:
When switching to RESP3 without authentication:
1) "proto"2) (integer) 33) "id"4) (integer) 123455) "modules"6) (empty array)
When switching to RESP2:
"OK"
Code Examples
dragonfly> HELLO 31) "proto"2) (integer) 33) "id"4) (integer) 123455) "modules"6) (empty array)dragonfly> HELLO 2"OK"dragonfly> HELLO 3 AUTH default mypassword SETNAME myclient1) "proto"2) (integer) 33) "id"4) (integer) 123465) "modules"6) (empty array)
Best Practices
- Ensure you use the correct protocol version for your application’s compatibility needs.
- Use the
AUTHoption securely by not hardcoding credentials in your application code. - Set meaningful client names with
SETNAMEfor easier tracking and debugging of client connections.
Common Mistakes
- Switching protocol versions without ensuring client support can cause unexpected behavior.
- Using incorrect or outdated credentials when
AUTHis necessary will result in authentication failure.
FAQs
What happens if I omit the protover parameter?
If protover is omitted, Redis responds with information about the current connection using the existing protocol.
Can I switch from RESP3 back to RESP2?
Yes, you can switch between RESP2 and RESP3 by issuing the HELLO command with the desired protover.