NewRedisClient creates Redis client
(cfg *RedisConfig)
| 52 | |
| 53 | // NewRedisClient creates Redis client |
| 54 | func NewRedisClient(cfg *RedisConfig) *RedisClient { |
| 55 | opt := &redis.UniversalOptions{ |
| 56 | Addrs: strings.Split(cfg.Endpoint, ","), |
| 57 | MasterName: cfg.MasterName, |
| 58 | Password: cfg.Password.Value, |
| 59 | DB: cfg.DB, |
| 60 | PoolSize: cfg.PoolSize, |
| 61 | IdleTimeout: cfg.IdleTimeout, |
| 62 | MaxConnAge: cfg.MaxConnAge, |
| 63 | } |
| 64 | if cfg.EnableTLS { |
| 65 | opt.TLSConfig = &tls.Config{InsecureSkipVerify: cfg.InsecureSkipVerify} |
| 66 | } |
| 67 | return &RedisClient{ |
| 68 | expiration: cfg.Expiration, |
| 69 | timeout: cfg.Timeout, |
| 70 | rdb: redis.NewUniversalClient(opt), |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | func (c *RedisClient) Ping(ctx context.Context) error { |
| 75 | var cancel context.CancelFunc |