You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.1 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package dbhelper
import (
"fmt"
"mygo/conf"
"time"
r "github.com/go-redis/redis/v7"
)
var queuedb *r.Client
func init() {
var addr string
fmt.Println("queuedb init")
addr = conf.GetQueueAddr()
fmt.Printf("GetQueueAddr addr = %v", addr)
queuedb = r.NewClient(&r.Options{
//连接信息
Network: "tcp", //网络类型tcp or unix默认tcp
Addr: addr, //主机名+冒号+端口默认localhost:6379
// Password: "", //密码
DB: 0, // redis数据库index
//连接池容量及闲置连接数量
PoolSize: 64, // 连接池最大socket连接数默认为4倍CPU数 4 * runtime.NumCPU
MinIdleConns: 10, //在启动阶段创建指定数量的Idle连接并长期维持idle状态的连接数不少于指定数量
//超时
DialTimeout: 5 * time.Second, //连接建立超时时间默认5秒。
ReadTimeout: 30 * time.Second, //读超时默认3秒 -1表示取消读超时
// WriteTimeout: 3 * time.Second, //写超时,默认等于读超时
// PoolTimeout: 4 * time.Second, //当所有连接都处在繁忙状态时,客户端等待可用连接的最大等待时长,默认为读超时+1秒。
// //闲置连接检查包括IdleTimeoutMaxConnAge
// IdleCheckFrequency: 60 * time.Second, //闲置连接检查的周期默认为1分钟-1表示不做周期性检查只在客户端获取连接时对闲置连接进行处理。
// IdleTimeout: 5 * time.Minute, //闲置超时默认5分钟-1表示取消闲置超时检查
// MaxConnAge: 0 * time.Second, //连接存活时长从创建开始计时超过指定时长则关闭连接默认为0即不关闭存活时长较长的连接
// //命令执行失败时的重试策略
// MaxRetries: 0, // 命令执行失败时最多重试多少次默认为0即不重试
// MinRetryBackoff: 8 * time.Millisecond, //每次计算重试间隔时间的下限默认8毫秒-1表示取消间隔
// MaxRetryBackoff: 512 * time.Millisecond, //每次计算重试间隔时间的上限默认512毫秒-1表示取消间隔
})
}
func GetQueueDb() *r.Client {
return queuedb
}