redis.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package init_serve
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/go-redis/redis/v8"
  6. "hongze/hz_crm_eta/global"
  7. "github.com/rdlucklib/rdluck_tools/cache"
  8. )
  9. func Redis() {
  10. redisConf := global.CONFIG.Redis
  11. client := redis.NewClient(&redis.Options{
  12. Addr: redisConf.Address,
  13. Password: redisConf.Password,
  14. DB: redisConf.Db,
  15. //PoolSize: 10, //连接池最大socket连接数,默认为10倍CPU数, 10 * runtime.NumCPU(暂不配置)
  16. })
  17. _, err := client.Ping(context.TODO()).Result()
  18. if err != nil {
  19. global.LOG.Error("redis 链接失败:", err)
  20. panic("redis 链接失败:" + err.Error())
  21. }
  22. //全局赋值redis链接
  23. global.Redis = client
  24. }
  25. func RedisTool() {
  26. fmt.Println("init RedisTool start")
  27. redisConf := global.CONFIG.Redis
  28. fmt.Println(redisConf)
  29. REDIS_CACHE := fmt.Sprintf(`{"key":"redis","conn":"%s","password":"%s"}`, redisConf.Address, redisConf.Password)
  30. fmt.Println("REDIS_CACHE:" + REDIS_CACHE)
  31. global.Rc, global.Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  32. if global.Re != nil {
  33. fmt.Println(global.Re)
  34. panic(global.Re)
  35. }
  36. fmt.Println("init RedisTool end")
  37. }