175 lines
3.7 KiB
Go
175 lines
3.7 KiB
Go
package cache
|
|
|
|
import (
|
|
"sync"
|
|
|
|
redis "github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
// 公共redis单例
|
|
var commonInstance *singleton
|
|
var commonOnce sync.Once
|
|
|
|
func CommonClient() *redis.Client {
|
|
return GetCommonRedisInstance().RedisClient
|
|
}
|
|
|
|
// 获取公用redis连接
|
|
func GetCommonRedisInstance() *singleton {
|
|
commonOnce.Do(func() {
|
|
commonInstance = &singleton{}
|
|
commonInstance.RedisClient = createCommonmRedisClient()
|
|
})
|
|
return commonInstance
|
|
}
|
|
|
|
// 用户redis单例
|
|
var userInstance *singleton
|
|
var userOnce sync.Once
|
|
|
|
func UserClient() *redis.Client {
|
|
return GetUserRedisInstance().RedisClient
|
|
}
|
|
|
|
// 获取公用redis连接
|
|
func GetUserRedisInstance() *singleton {
|
|
userOnce.Do(func() {
|
|
userInstance = &singleton{}
|
|
userInstance.RedisClient = createUserRedisClient()
|
|
})
|
|
return userInstance
|
|
}
|
|
|
|
// 用户关系redis单例
|
|
var relationInstance *singleton
|
|
var relationOnce sync.Once
|
|
|
|
// 获取relation redis连接
|
|
func GetUserRelationRedisInstance() *singleton {
|
|
relationOnce.Do(func() {
|
|
relationInstance = &singleton{}
|
|
relationInstance.RedisClient = createUserRelationRedisClient()
|
|
})
|
|
return relationInstance
|
|
}
|
|
|
|
// 动态redis单例
|
|
var timelineInstance *singleton
|
|
var timelineOnce sync.Once
|
|
|
|
// 获取动态redis连接
|
|
func GetTimelineRedisInstance() *singleton {
|
|
timelineOnce.Do(func() {
|
|
timelineInstance = &singleton{}
|
|
timelineInstance.RedisClient = createTimelineRedisClient()
|
|
})
|
|
return timelineInstance
|
|
}
|
|
|
|
// 活动redis单例
|
|
var activityInstance *singleton
|
|
var activityOnce sync.Once
|
|
|
|
func ActivityClient() *redis.Client {
|
|
return GetActivityRedisInstance().RedisClient
|
|
}
|
|
|
|
// 获取活动redis连接
|
|
func GetActivityRedisInstance() *singleton {
|
|
activityOnce.Do(func() {
|
|
activityInstance = &singleton{}
|
|
activityInstance.RedisClient = createActivityRedisClient()
|
|
})
|
|
return activityInstance
|
|
}
|
|
|
|
// 公会redis单例
|
|
var guildInstance *singleton
|
|
var guildOnce sync.Once
|
|
|
|
func GuildClient() *redis.Client {
|
|
return GetGuildRedisInstance().RedisClient
|
|
}
|
|
|
|
// 获取公会redis连接
|
|
func GetGuildRedisInstance() *singleton {
|
|
guildOnce.Do(func() {
|
|
guildInstance = &singleton{}
|
|
guildInstance.RedisClient = createGuildRedisClient()
|
|
})
|
|
return guildInstance
|
|
}
|
|
|
|
// 聊天室redis单例
|
|
var chatroomInstance *singleton
|
|
var chatroomOnce sync.Once
|
|
|
|
func RoomClient() *redis.Client {
|
|
return GetChatroomRedisInstance().RedisClient
|
|
}
|
|
|
|
// 获取chatroom redis连接
|
|
func GetChatroomRedisInstance() *singleton {
|
|
chatroomOnce.Do(func() {
|
|
chatroomInstance = &singleton{}
|
|
chatroomInstance.RedisClient = createChatroomRedisClient()
|
|
})
|
|
return chatroomInstance
|
|
}
|
|
|
|
// SESSION redis单例
|
|
var sessionInstance *singleton
|
|
var sessionOnce sync.Once
|
|
|
|
// 获取Session redis连接
|
|
func GetSessionRedisInstance() *singleton {
|
|
sessionOnce.Do(func() {
|
|
sessionInstance = &singleton{}
|
|
sessionInstance.RedisClient = createSessionRedisClient()
|
|
})
|
|
return sessionInstance
|
|
}
|
|
|
|
// 技能订单redis单例
|
|
var skillInstance *singleton
|
|
var skillOnce sync.Once
|
|
|
|
// 获取用户关系redis连接
|
|
func GetSkillRedisInstance() *singleton {
|
|
skillOnce.Do(func() {
|
|
skillInstance = &singleton{}
|
|
skillInstance.RedisClient = createSkillRedisClient()
|
|
})
|
|
return skillInstance
|
|
}
|
|
|
|
// 活动redis单例
|
|
var imInstance *singleton
|
|
var imOnce sync.Once
|
|
|
|
// 获取用户关系redis连接
|
|
func GetIMRedisInstance() *singleton {
|
|
imOnce.Do(func() {
|
|
imInstance = &singleton{}
|
|
imInstance.RedisClient = createIMRedisClient()
|
|
})
|
|
return imInstance
|
|
}
|
|
|
|
// Cms系统 redis单例
|
|
var cmsInstance *singleton
|
|
var cmsOnce sync.Once
|
|
|
|
func CmsClient() *redis.Client {
|
|
return GetCmsRedisInstance().RedisClient
|
|
}
|
|
|
|
// 获取公用redis连接
|
|
func GetCmsRedisInstance() *singleton {
|
|
cmsOnce.Do(func() {
|
|
cmsInstance = &singleton{}
|
|
cmsInstance.RedisClient = createCmsRedisClient()
|
|
})
|
|
return cmsInstance
|
|
}
|