This page introduces how to configure Asynq to use Redis Sentinel to avoid downtime caused by Redis failures.
Prerequisites
Please read the documentation on Redis Sentinel to understand the topic.
Configure Asynq to use Redis Sentinels
It's very simple to configure asynq
's Client
and Server
to use Redis Sentinel. Use RedisFailoverClientOpt
to specify the name of the Redis master node and the addresses of Redis Sentinels.
var redis = &asynq.RedisFailoverClientOpt{
MasterName: "mymaster",
SentinelAddrs: []string{"localhost:5000", "localhost:5001", "localhost:5002"},
}
Then pass this client option to NewClient
and NewBackground
to create an instance using Redis Sentinels.
client := asynq.NewClient(redis)
// ...
srv := asynq.NewServer(redis, asynq.Config{ Concurrency: 10 })
With this configuration, when the Redis master node fails, Sentinels will initiate the failover process and notify asynq
of the new master node, and background task processing will continue to work normally.