redis.go 615 B

12345678910111213141516171819202122232425
  1. package init_serve
  2. import (
  3. "context"
  4. "github.com/go-redis/redis/v8"
  5. "hongze/hongze_yb/global"
  6. )
  7. func Redis() {
  8. redisConf := global.CONFIG.Redis
  9. client := redis.NewClient(&redis.Options{
  10. Addr: redisConf.Address,
  11. Password: redisConf.Password,
  12. DB: redisConf.Db,
  13. //PoolSize: 10, //连接池最大socket连接数,默认为10倍CPU数, 10 * runtime.NumCPU(暂不配置)
  14. })
  15. _, err := client.Ping(context.TODO()).Result()
  16. if err != nil {
  17. global.LOG.Error("redis 链接失败:", err)
  18. panic("redis 链接失败:" + err.Error())
  19. }
  20. //全局赋值redis链接
  21. global.Redis = client
  22. }