redis.go 660 字节
package redis

import (
	"fmt"
	"oppmg/common/log"

	"github.com/go-redis/redis"
)

//时间
const (
	SECOND int64 = 1           //秒
	MINUTE int64 = SECOND * 60 //分
	HOUR   int64 = MINUTE * 60 //小时
	DAY    int64 = HOUR * 24
	WEEK   int64 = DAY * 7
)

var RedisClient *redis.Client

func SetRedis(addr string, password string, db int) {
	log.Info("初始化redis")
	RedisClient = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: password,
		DB:       db, //使用的库
	})
	_, err := RedisClient.Ping().Result()
	if err != nil {
		panic(fmt.Sprintf("connect redis err:%s", err))
	}
}

func GetRedis() *redis.Client {
	return RedisClient
}