Implement lab 3 level 4 failover and idempotency
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func NewRedis(ctx context.Context, addr string) (*redis.Client, error) {
|
||||
|
||||
options := &redis.Options{
|
||||
Addr: addr,
|
||||
DialTimeout: 3 * time.Second,
|
||||
ReadTimeout: 3 * time.Second,
|
||||
WriteTimeout: 2 * time.Second,
|
||||
PoolSize: 10,
|
||||
PoolTimeout: 2 * time.Second,
|
||||
ContextTimeoutEnabled: true,
|
||||
}
|
||||
|
||||
client := redis.NewClient(options)
|
||||
|
||||
if err := client.Ping(ctx).Err(); err != nil {
|
||||
_ = client.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user