first commit

This commit is contained in:
Yangtao
2025-11-18 17:48:20 +08:00
commit 6e56cab848
196 changed files with 65809 additions and 0 deletions

163
pkg/cache/redis_client.go vendored Normal file
View File

@ -0,0 +1,163 @@
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
}