package util

import (
	"github.com/go-redis/redis"
	"strconv"
)

// RedisClient Redis缓存客户端单例
type Redis struct {
	Db        string
	Addr      string
	Password  string
	Client    *redis.Client
	ConnTimes int
	stop      bool
}

// Redis 在中间件中初始化redis链接
func Connect(dbs string, addr string, password string) *redis.Client {
	db, _ := strconv.ParseUint(dbs, 10, 64)
	client := redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: password,
		DB:       int(db),
	})

	_, err := client.Ping().Result()
	if err != nil {
		panic("redis connect err: " + dbs + " " + addr + " " + password)
	}

	return client
}
