redis_conn.go 372 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
package redis_manager

import (
	"sync"
)

var (
	def           Redis
	defaultConfig RedisConfig
	defLocker     sync.Locker
)

func SetDefault(r Redis) {
	def = r
}

// 获取redis连接
func GetConnection() Redis {
	if def != nil {
		return def
	}

	defLocker.Lock()
	defer defLocker.Unlock()

	if def != nil {
		return def
	}

	def = Create(defaultConfig)
	return def
}