PING
Introduction and Use Case(s)
The PING command in Redis is used to check the connection to the server. It’s a simple way to verify that the server is running and responding. It’s commonly used in health checks, monitoring scripts, or client libraries to ensure the connection to the Redis server is alive.
Syntax
PING [message]
Parameter Explanations
message: An optional parameter. If provided, Redis will return this message instead of the default “PONG”.
Return Values
- Without the
messageparameter: Returns the string “PONG”. - With the
messageparameter: Returns the message provided as input.
Code Examples
dragonfly> PING"PONG"dragonfly> PING "Hello, Redis!""Hello, Redis!"
Best Practices
- Use
PINGperiodically in your application to ensure the Redis connection is healthy. - Combine
PINGwith other monitoring commands to get a comprehensive view of server health.
Common Mistakes
- Overusing
PINGcan add unnecessary load to your Redis server. Use it judiciously within your monitoring or health check routines.
FAQs
Is PING useful for checking latency?
No, PING is primarily for connectivity checks. For latency measurements, consider using the LATENCY DOCTOR command.
Can PING be used in Redis Cluster?
Yes, PING works the same way in Redis Cluster as it does in a standalone Redis instance.