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

  1. 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. Both username and password must 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. 1) "proto"
    2. 2) (integer) 3
    3. 3) "id"
    4. 4) (integer) 12345
    5. 5) "modules"
    6. 6) (empty array)
  • When switching to RESP2:

    1. "OK"

Code Examples

  1. dragonfly> HELLO 3
  2. 1) "proto"
  3. 2) (integer) 3
  4. 3) "id"
  5. 4) (integer) 12345
  6. 5) "modules"
  7. 6) (empty array)
  8. dragonfly> HELLO 2
  9. "OK"
  10. dragonfly> HELLO 3 AUTH default mypassword SETNAME myclient
  11. 1) "proto"
  12. 2) (integer) 3
  13. 3) "id"
  14. 4) (integer) 12346
  15. 5) "modules"
  16. 6) (empty array)

Best Practices

  • Ensure you use the correct protocol version for your application’s compatibility needs.
  • Use the AUTH option securely by not hardcoding credentials in your application code.
  • Set meaningful client names with SETNAME for 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 AUTH is 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.