# 6.8 Client redis

# 范式

参考地址 (opens new window)

# RedisConfig

# 配置项

名称 类型 描述
master.addr string 主节点dns连接地址,包含用户名密码
slaves.addr []string 从节点dns连接地址 包含用户名密码
db int 默认为0, 一般应用不推荐使用DB分片
poolSize int 每个节点的最大连接池限制 默认200个连接
maxRetries int 网络相关的错误最大重试次数,默认0次
minIdleConns int 最小空闲连接数,默认20
dialTimeout time.Duration 拨超时时间,默认3s
readTimeout time.Duration 读超时,默认1s
writeTimeout time.Duration 写超时,默认1s
idleTimeout int 连接最大空闲时间,默认60s, 超过该时间,连接会被主动关闭
readOnMaster bool 是否开启主节点读,默认true
debug bool 是否开启debug,默认false
slowThreshold bool 慢日志记录阈值,默认250ms
enableMetric bool 是否开启metric上报,默认true
enableTrace bool 是否开启trace,默认true
enableAccessLog bool 是否开启access记录,默认false
....

# 示例

[jupiter.redis]
    [jupiter.redis.test]
        [jupiter.redis.test.stub]
            dialTimeout="2s"
            readTimeout="5s"
            idleTimeout="60s"
            debug=true
            [jupiter.redis.test.stub.master]
                addr="redis://username:password@127.0.0.1:6379" # password可包含:
            [jupiter.redis.test.stub.slaves]
                addr=[
                    "redis://username:password@127.0.0.2:6379",# password可包含:
                ]
1
2
3
4
5
6
7
8
9
10
11
12
13

addr是dns连接包含用户名密码

  • 无密码写法 redis://127.0.0.2:6379
  • 无用户名有密码写法
    redis://:password@127.0.0.2:6379 password前的:不可缺省
  • 有用户名有密码写法
    redis://username:password@127.0.0.2:6379

# RedisClusterConfig

暂不支持,后面有需要再加