Production usage
Get your go-redis
app ready for production
This guide offers recommendations to get the best reliability and performance in your production environment.
Checklist
Each item in the checklist below links to the section for a recommendation. Use the checklist icons to record your progress in implementing the recommendations.
Recommendations
The sections below offer recommendations for your production environment. Some of them may not apply to your particular use case.
Health checks
If your code doesn't access the Redis server continuously then it
might be useful to make a "health check" periodically (perhaps once
every few seconds). You can do this using a simple
PING
command:
err := rdb.Ping(ctx).Err()
if err != nil {
// Report failed health check.
}
Health checks help to detect problems as soon as possible without waiting for a user to report them.
Error handling
The Result()
method of a command returns both the command result
and an error value. Although you are mainly interested in the result,
you should also always check that the error value is nil
before
proceeding. Errors can be returned for failed connections, network
problems, and invalid command parameters, among other things.
Monitor performance and errors
go-redis
supports OpenTelemetry. This lets
you trace command execution and monitor your server's performance.
You can use this information to detect problems before they are reported
by users. See Observability
for more information.