Documentation ¶
Index ¶
- Constants
- func NewRedisClient(config *Config, opts ...Option) redis.UniversalClient
- type ClusterConfig
- type Config
- type Option
- func WithAddr(addr string) Option
- func WithCluster(cc ClusterConfig) Option
- func WithCompatible(b bool) Option
- func WithConcurrency(size int) Option
- func WithConnectTimeout(timeout time.Duration) Option
- func WithDB(num int) Option
- func WithIdleTimeout(idleTimeout time.Duration) Option
- func WithMaxConnAge(maxConnAge time.Duration) Option
- func WithMaxRetries(maxRetries int) Option
- func WithMaxRetry(maxRetry int) Option
- func WithMinBatchCount(n int) Option
- func WithMinIdleConns(minIdleConns int) Option
- func WithPoolSize(poolSize int) Option
- func WithPoolTimeout(poolTimeout time.Duration) Option
- func WithPwd(pwd string) Option
- func WithReadTimeout(timeout time.Duration) Option
- func WithSentinel(sc SentinelConfig) Option
- func WithTLSConfig(tlsConfig *tls.Config) Option
- func WithUsername(username string) Option
- func WithWaitTime(t time.Duration) Option
- func WithWriteTimeout(timeout time.Duration) Option
- type Pool
- type RedisObject
- type Resp
- type SentinelConfig
- type StandaloneConfig
- type Task
Constants ¶
const ( // Get get method define Get = iota // Set set method define Set // Del del method define Del // Sadd del method define Sadd // Srem del method define Srem )
Variables ¶
This section is empty.
Functions ¶
func NewRedisClient ¶
NewRedisClient new redis client
Types ¶
type ClusterConfig ¶
type ClusterConfig struct { // A seed list of host:port addresses of cluster nodes. Addrs []string // Enables read-only commands on slave nodes. ReadOnly bool // Allows routing read-only commands to the closest master or slave node. // It automatically enables ReadOnly. RouteByLatency bool // Allows routing read-only commands to the random master or slave node. // It automatically enables ReadOnly. RouteRandomly bool }
ClusterConfig redis cluster pool configuration See github.com/go-redis/redis/v8/redis.ClusterOptions
type Config ¶
type Config struct { // DeployMode is the run mode of the redis pool, support `standalone`、`cluster`、`sentinel`、or `ckv` DeployMode string `json:"deployMode"` // StandaloneConfig standalone-deploy-mode config StandaloneConfig // StandaloneConfig sentinel-deploy-mode config SentinelConfig // ClusterConfig cluster-deploy-mode config ClusterConfig }
Config redis pool configuration
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig redis pool configuration with default values
func (*Config) ClusterOptions ¶
func (c *Config) ClusterOptions() *redis.ClusterOptions
ClusterOptions cluster-mode client options
func (*Config) FailOverOptions ¶
func (c *Config) FailOverOptions() *redis.FailoverOptions
FailOverOptions sentinel-model options
func (*Config) StandaloneOptions ¶
func (c *Config) StandaloneOptions() *redis.Options
StandaloneOptions standalone-mode options
func (*Config) UnmarshalJSON ¶
UnmarshalJSON unmarshal config from json
type Option ¶
type Option func(c *Config)
Option functional options for Config
func WithConnectTimeout ¶
WithConnectTimeout set connection timeout
func WithIdleTimeout ¶
WithIdleTimeout set idleTimeout
func WithMaxConnAge ¶
WithMaxConnAge set MaxConnAge
func WithMinIdleConns ¶
WithMinIdleConns set minIdleConns
func WithPoolTimeout ¶
WithPoolTimeout set pool timeout
func WithReadTimeout ¶
WithReadTimeout set readTimeout
func WithWriteTimeout ¶
WithWriteTimeout set writeTimeout
type Pool ¶
type Pool interface { // Start 启动ckv连接池工作 Start() // Sdd 使用连接池,向redis发起Sdd请求 Sdd(id string, members []string) *Resp // Srem 使用连接池,向redis发起Srem请求 Srem(id string, members []string) *Resp // Get 使用连接池,向redis发起Get请求 Get(id string) *Resp // Set 使用连接池,向redis发起Set请求 Set(id string, redisObj RedisObject) *Resp // Del 使用连接池,向redis发起Del请求 Del(id string) *Resp // RecoverTimeSec the time second record when recover RecoverTimeSec() int64 }
type RedisObject ¶
type RedisObject interface { // Serialize 序列化成字符串 Serialize(compatible bool) string // Deserialize 反序列为对象 Deserialize(value string, compatible bool) error }
RedisObject 序列化对象
type Resp ¶
type Resp struct { Value string Err error Exists bool Compatible bool // contains filtered or unexported fields }
Resp ckv任务结果
type SentinelConfig ¶
type SentinelConfig struct { // MasterName is the name of the master instance MasterName string `json:"masterName"` // A seed list of host:port addresses of sentinel servers. // Use shor name, to keep in line with ClusterConfig.Addrs Addrs []string `json:"addrs"` // Username ACL User and Password SentinelUsername string `json:"sentinelUsername"` // Password ACL User and Password SentinelPassword string `json:"sentinelPassword"` // Route all commands to slave read-only nodes. SlaveOnly bool // Use slaves disconnected with master when cannot get connected slaves // Now, this option only works in RandomSlaveAddr function. UseDisconnectedSlaves bool }
SentinelConfig sentinel pool configuration. See github.com/go-redis/redis/v8/redis.FailoverOptions
type StandaloneConfig ¶
type StandaloneConfig struct { // KvAddr is the address of the redis server KvAddr string `json:"kvAddr"` // 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. KvUser string `json:"kvUser"` // KvPasswd for go-redis password or username (redis 6.0 version) // 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. KvPasswd string `json:"kvPasswd"` // Minimum number of idle connections which is useful when establishing // new connection is slow. MinIdleConns int `json:"minIdleConns"` // 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 time.Duration `json:"idleTimeout"` // ConnectTimeout for go-redis is Dial timeout for establishing new connections. // Default is 5 seconds. ConnectTimeout time.Duration `json:"connectTimeout"` MsgTimeout time.Duration `json:"msgTimeout"` Concurrency int `json:"concurrency"` Compatible bool `json:"compatible"` MaxRetry int `json:"maxRetry"` MinBatchCount int `json:"minBatchCount"` WaitTime time.Duration `json:"waitTime"` // MaxRetries is Maximum number of retries before giving up. // Default is 3 retries; -1 (not 0) disables retries. MaxRetries int `json:"maxRetries"` // DB is Database to be selected after connecting to the server. DB int `json:"DB"` // ReadTimeout 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 time.Duration `json:"readTimeout"` // WriteTimeout for socket writes. If reached, commands will fail // with a timeout instead of blocking. // Default is ReadTimeout. WriteTimeout time.Duration `json:"writeTimeout"` // Maximum number of socket connections. // Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS. PoolSize int `json:"poolSize" mapstructure:"poolSize"` // 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:"poolTimeout"` // Connection age at which client retires (closes) the connection. // Default is to not close aged connections. MaxConnAge time.Duration `json:"maxConnAge"` // WithTLS whether open TLSConfig // if WithTLS is true, you should call WithEnableWithTLS,and then TLSConfig is not should be nil // In this case you should call WithTLSConfig func to set tlsConfig WithTLS bool `json:"withTLS"` // contains filtered or unexported fields }
StandaloneConfig redis pool basic-configuration, also used as sentinel/cluster common config.