审查视图

pkg/infrastructure/cache/redis.go 1.1 KB
tangxuhui authored
1 2 3 4
package cache

import (
	"fmt"
yangfu authored
5
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
tangxuhui authored
6 7 8 9 10 11 12

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

var clientRedis *redis.Client

const (
tangxuhui authored
13
	KEY_PREFIX string = "allied:creation:gateway:"
tangxuhui authored
14 15
)
16
func InitRedist() *redis.Client {
tangxuhui authored
17 18
	options := redis.Options{
		Network:            "tcp",
yangfu authored
19
		Addr:               fmt.Sprintf("%s:%s", constant.REDIS_HOST, constant.REDIS_PORT),
tangxuhui authored
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
		Dialer:             nil,
		OnConnect:          nil,
		Password:           "",
		DB:                 1,
		MaxRetries:         0,
		MinRetryBackoff:    0,
		MaxRetryBackoff:    0,
		DialTimeout:        0,
		ReadTimeout:        0,
		WriteTimeout:       0,
		PoolSize:           0,
		MinIdleConns:       0,
		MaxConnAge:         0,
		PoolTimeout:        0,
		IdleTimeout:        0,
		IdleCheckFrequency: 0,
		TLSConfig:          nil,
	}
	// 新建一个client
	clientRedis = redis.NewClient(&options)
40 41 42 43 44
	pong, err := clientRedis.Ping().Result()
	if err != nil {
		e := fmt.Errorf("redis 连接失败,%s,%w", pong, err)
		panic(e)
	}
tangxuhui authored
45 46
	return clientRedis
}
yangfu authored
47 48 49 50

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