diff --git a/config.go b/config.go index e024af3..715be24 100644 --- a/config.go +++ b/config.go @@ -8,6 +8,8 @@ package redis import ( + "time" + "git.zhangdeman.cn/zhangdeman/logger" ) @@ -28,13 +30,78 @@ type FullConfig struct { // // Date : 11:52 2022/6/15 type Config struct { - Host string `yaml:"host" json:"host"` // 地址 - Port int `yaml:"port" json:"port"` // 端口 - DB int `yaml:"db" json:"db"` // db索引 - User string `json:"user" yaml:"user"` // 账号 - Password string `yaml:"password" json:"password"` // 密码 - Timeout Timeout `yaml:"timeout" json:"timeout"` // 超时配置 - MaxConnection int `json:"max_connection" yaml:"max_connection"` // 最大连接数 + Network string `json:"network" yaml:"network"` // 连接方式 tcp 或 unix , 默认 tcp + Host string `yaml:"host" json:"host"` // 地址 + Port int `yaml:"port" json:"port"` // 端口 + + // Dialer creates new network connection and has priority over + // Network and Addr options. + // Dialer func(ctx context.Context, network, addr string) (net.Conn, error) + + // Hook that is called when new connection is established. + // OnConnect func(ctx context.Context, cn *redis.Conn) error + + // Use the specified Username to authenticate the current connection + // with one of the connections defined in the ACL list when connecting + // to a Redis 6.0 instance, or greater, that is using the Redis ACL system. + Username string `json:"username" yaml:"username"` // 账号 + // Optional password. Must match the password specified in the + // requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower), + // or the User Password when connecting to a Redis 6.0 instance, or greater, + // that is using the Redis ACL system. + Password string `json:"password" yaml:"password"` // 密码 + + // Database to be selected after connecting to the server. + DB int `json:"db" yaml:"db"` // 选中的数据库 + + // Maximum number of retries before giving up. + // Default is 3 retries; -1 (not 0) disables retries. + MaxRetries int `json:"max_retries" yaml:"max_retries"` // 最大重试次数, 默认 3 , -1 为不重试 + // Minimum backoff between each retry. + // Default is 8 milliseconds; -1 disables backoff. + MinRetryBackoff int64 `json:"min_retry_backoff" yaml:"min_retry_backoff"` // 最小重试的时间间隔, 默认 8ms, -1禁用 + // Maximum backoff between each retry. + // Default is 512 milliseconds; -1 disables backoff. + MaxRetryBackoff int `json:"max_retry_backoff" yaml:"max_retry_backoff"` // 最大重试的时间间隔, 默认 512ms, -1禁用 + + // Dial timeout for establishing new connections. + // Default is 5 seconds. + DialTimeout int64 `json:"dial_timeout" yaml:"dial_timeout"` // 建立新连接的超时时间, 默认 5s + // Timeout for socket reads. If reached, commands will fail + // with a timeout instead of blocking. Use value -1 for no timeout and 0 for default. + // Default is 3 seconds. + ReadTimeout int64 `json:"read_timeout" yaml:"read_timeout"` // 读取超时时间,默认 3s , -1 不设置超时 + // Timeout for socket writes. If reached, commands will fail + // with a timeout instead of blocking. + // Default is ReadTimeout. + WriteTimeout int64 `json:"write_timeout" yaml:"write_timeout"` // 写入超时时间, 默认值和 ReadTimeout 配置一致 + + // Type of connection pool. + // true for FIFO pool, false for LIFO pool. + // Note that fifo has higher overhead compared to lifo. + PoolFIFO bool `json:"pool_fifo" yaml:"pool_fifo"` // 连接吃采用 FIFO + // Maximum number of socket connections. + // Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS. + PoolSize int `json:"pool_size" yaml:"pool_size"` // 连接池大小, 默认 runtime.GOMAXPROCS * 10 + // Minimum number of idle connections which is useful when establishing + // new connection is slow. + MinIdleConns int `json:"min_idle_conns" yaml:"min_idle_conns"` // 最小的 空闲 连接数数量 + // Connection age at which client retires (closes) the connection. + // Default is to not close aged connections. + MaxConnAge int64 `json:"max_conn_age" yaml:"max_conn_age"` // 连接最大的存活时常 + // Amount of time client waits for connection if all connections + // are busy before returning an error. + // Default is ReadTimeout + 1 second. + PoolTimeout time.Duration `json:"pool_timeout" yaml:"pool_timeout"` // 连接池无可用连接, 等待的时常, 默认值 ReadTimeout + 1 + // Amount of time after which client closes idle connections. + // Should be less than server's timeout. + // Default is 5 minutes. -1 disables idle timeout check. + IdleTimeout int64 `json:"idle_timeout" yaml:"idle_timeout"` // 空闲链接的超时时间, 默认 5 分钟 -1 金童 + // Frequency of idle checks made by idle connections reaper. + // Default is 1 minute. -1 disables idle connections reaper, + // but idle connections are still discarded by the client + // if IdleTimeout is set. + IdleCheckFrequency int64 `json:"idle_check_frequency" yaml:"idle_check_frequency"` // 空闲连接检查频率, 默认 1 分钟, -1 禁用, 注意 : 即使禁用,超过 IdleTimeout 时常的连接也不可被读取到 } // Timeout 超时配置