164 lines
4.8 KiB
Go
164 lines
4.8 KiB
Go
package cache
|
||
|
||
import (
|
||
logs "servicebase/pkg/log"
|
||
"context"
|
||
|
||
redis "github.com/redis/go-redis/v9"
|
||
"github.com/spf13/viper"
|
||
)
|
||
|
||
type singleton struct {
|
||
RedisClient *redis.Client
|
||
}
|
||
|
||
func Ctx() context.Context {
|
||
return context.Background()
|
||
}
|
||
|
||
// 创建公共的redis
|
||
func createCommonmRedisClient() *redis.Client {
|
||
client := redis.NewClient(&redis.Options{
|
||
Addr: viper.GetString("redis.default.addr"),
|
||
Password: viper.GetString("redis.default.pass"),
|
||
DB: 0,
|
||
PoolSize: 32,
|
||
MinIdleConns: 4,
|
||
})
|
||
logs.Info("#REDIS#" + "创建一个 common redis连接池,返回一个连接" + "#REDIS#")
|
||
return client
|
||
}
|
||
|
||
// 创建user的redis
|
||
func createUserRedisClient() *redis.Client {
|
||
client := redis.NewClient(&redis.Options{
|
||
Addr: viper.GetString("redis.default.addr"),
|
||
Password: viper.GetString("redis.default.pass"), // no password set
|
||
DB: 1,
|
||
PoolSize: 32,
|
||
MinIdleConns: 4,
|
||
})
|
||
|
||
logs.Info("#REDIS#" + "创建一个 user redis连接池,返回一个连接" + "#REDIS#")
|
||
return client
|
||
}
|
||
|
||
// 创建relation的redis
|
||
func createUserRelationRedisClient() *redis.Client {
|
||
client := redis.NewClient(&redis.Options{
|
||
Addr: viper.GetString("redis.default.addr"),
|
||
Password: viper.GetString("redis.default.pass"), // no password set
|
||
DB: 2,
|
||
PoolSize: 32,
|
||
MinIdleConns: 4,
|
||
})
|
||
logs.Info("#REDIS#" + "创建一个 relation redis连接池,返回一个连接" + "#REDIS#")
|
||
return client
|
||
}
|
||
|
||
// 创建timeline的redis
|
||
func createTimelineRedisClient() *redis.Client {
|
||
client := redis.NewClient(&redis.Options{
|
||
Addr: viper.GetString("redis.default.addr"),
|
||
Password: viper.GetString("redis.default.pass"), // no password set
|
||
DB: 3,
|
||
PoolSize: 32,
|
||
MinIdleConns: 4,
|
||
})
|
||
logs.Info("#REDIS#" + "创建一个 timeline redis连接池,返回一个连接" + "#REDIS#")
|
||
return client
|
||
}
|
||
|
||
// 创建活动的redis
|
||
func createActivityRedisClient() *redis.Client {
|
||
client := redis.NewClient(&redis.Options{
|
||
Addr: viper.GetString("redis.activity.addr"),
|
||
Password: viper.GetString("redis.activity.pass"), // no password set
|
||
DB: viper.GetInt("redis.activity.db"),
|
||
PoolSize: 32,
|
||
MinIdleConns: 4,
|
||
})
|
||
logs.Info("#REDIS#" + "创建一个 activity redis连接池,返回一个连接" + "#REDIS#")
|
||
return client
|
||
}
|
||
|
||
// 创建俱乐部的redis
|
||
func createGuildRedisClient() *redis.Client {
|
||
client := redis.NewClient(&redis.Options{
|
||
Addr: viper.GetString("redis.guild.addr"),
|
||
Password: viper.GetString("redis.guild.pass"), // no password set
|
||
DB: viper.GetInt("redis.guild.db"),
|
||
PoolSize: 32,
|
||
MinIdleConns: 4,
|
||
})
|
||
logs.Info("#REDIS#" + "创建一个 guild redis连接池,返回一个连接" + "#REDIS#")
|
||
return client
|
||
}
|
||
|
||
// 创建chatroom的redis
|
||
func createChatroomRedisClient() *redis.Client {
|
||
client := redis.NewClient(&redis.Options{
|
||
Addr: viper.GetString("redis.default.addr"),
|
||
Password: viper.GetString("redis.default.pass"), // no password set
|
||
DB: 6,
|
||
PoolSize: 32,
|
||
MinIdleConns: 4,
|
||
})
|
||
logs.Info("#REDIS#" + "创建一个 chatroom redis连接池,返回一个连接" + "#REDIS#")
|
||
return client
|
||
}
|
||
|
||
// 创建session的redis
|
||
func createSessionRedisClient() *redis.Client {
|
||
client := redis.NewClient(&redis.Options{
|
||
Addr: viper.GetString("redis.default.addr"),
|
||
Password: viper.GetString("redis.default.pass"), // no password set
|
||
DB: 7,
|
||
PoolSize: 32,
|
||
MinIdleConns: 4,
|
||
})
|
||
logs.Info("#REDIS#" + "创建一个 session redis连接池,返回一个连接" + "#REDIS#")
|
||
return client
|
||
}
|
||
|
||
// 创建用户关系的redis
|
||
func createSkillRedisClient() *redis.Client {
|
||
client := redis.NewClient(&redis.Options{
|
||
Addr: viper.GetString("redis.default.addr"),
|
||
Password: viper.GetString("redis.default.pass"), // no password set
|
||
DB: 8,
|
||
PoolSize: 32,
|
||
MinIdleConns: 4,
|
||
})
|
||
logs.Info("#REDIS#" + "创建一个 skill redis连接池,返回一个连接" + "#REDIS#")
|
||
return client
|
||
}
|
||
|
||
// 创建IM的redis
|
||
func createIMRedisClient() *redis.Client {
|
||
client := redis.NewClient(&redis.Options{
|
||
Addr: viper.GetString("redis.default.addr"),
|
||
Password: viper.GetString("redis.default.pass"), // no password set
|
||
DB: 10,
|
||
PoolSize: 32,
|
||
MinIdleConns: 4,
|
||
})
|
||
logs.Info("#REDIS#" + "创建一个 im redis连接池,返回一个连接" + "#REDIS#")
|
||
return client
|
||
}
|
||
|
||
// 创建CMS的redis
|
||
func createCmsRedisClient() *redis.Client {
|
||
redisHost := viper.GetString("redis.default.addr")
|
||
redisPwd := viper.GetString("redis.default.pass")
|
||
client := redis.NewClient(&redis.Options{
|
||
Addr: redisHost,
|
||
Password: redisPwd,
|
||
DB: 11,
|
||
PoolSize: 32,
|
||
MinIdleConns: 4,
|
||
})
|
||
logs.Info("#REDIS#" + "创建一个 cms redis连接池,返回一个连接" + "#REDIS#")
|
||
return client
|
||
}
|