123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package init_serve
- import (
- "context"
- "fmt"
- "github.com/go-redis/redis/v8"
- "hongze/hz_crm_eta/global"
- "github.com/rdlucklib/rdluck_tools/cache"
- )
- func Redis() {
- redisConf := global.CONFIG.Redis
- client := redis.NewClient(&redis.Options{
- Addr: redisConf.Address,
- Password: redisConf.Password,
- DB: redisConf.Db,
- //PoolSize: 10, //连接池最大socket连接数,默认为10倍CPU数, 10 * runtime.NumCPU(暂不配置)
- })
- _, err := client.Ping(context.TODO()).Result()
- if err != nil {
- global.LOG.Error("redis 链接失败:", err)
- panic("redis 链接失败:" + err.Error())
- }
- //全局赋值redis链接
- global.Redis = client
- }
- func RedisTool() {
- fmt.Println("init RedisTool start")
- redisConf := global.CONFIG.Redis
- fmt.Println(redisConf)
- REDIS_CACHE := fmt.Sprintf(`{"key":"redis","conn":"%s","password":"%s"}`, redisConf.Address, redisConf.Password)
- fmt.Println("REDIS_CACHE:" + REDIS_CACHE)
- global.Rc, global.Re = cache.NewCache(REDIS_CACHE) //初始化缓存
- if global.Re != nil {
- fmt.Println(global.Re)
- panic(global.Re)
- }
- fmt.Println("init RedisTool end")
- }
|