redispool

package
v1.18.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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

func NewRedisClient(config *Config, opts ...Option) redis.UniversalClient

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

func (c *Config) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshal config from json

func (*Config) Validate

func (c *Config) Validate() error

Validate validate config params

type Option

type Option func(c *Config)

Option functional options for Config

func WithAddr

func WithAddr(addr string) Option

WithAddr set redis addr

func WithCluster

func WithCluster(cc ClusterConfig) Option

WithCluster use redis cluster

func WithCompatible

func WithCompatible(b bool) Option

WithCompatible set Compatible

func WithConcurrency

func WithConcurrency(size int) Option

WithConcurrency set concurrency size

func WithConnectTimeout

func WithConnectTimeout(timeout time.Duration) Option

WithConnectTimeout set connection timeout

func WithDB

func WithDB(num int) Option

WithDB set redis db

func WithIdleTimeout

func WithIdleTimeout(idleTimeout time.Duration) Option

WithIdleTimeout set idleTimeout

func WithMaxConnAge

func WithMaxConnAge(maxConnAge time.Duration) Option

WithMaxConnAge set MaxConnAge

func WithMaxRetries

func WithMaxRetries(maxRetries int) Option

WithMaxRetries set maxRetries

func WithMaxRetry

func WithMaxRetry(maxRetry int) Option

WithMaxRetry set pool MaxRetry

func WithMinBatchCount

func WithMinBatchCount(n int) Option

WithMinBatchCount set MinBatchCount

func WithMinIdleConns

func WithMinIdleConns(minIdleConns int) Option

WithMinIdleConns set minIdleConns

func WithPoolSize

func WithPoolSize(poolSize int) Option

WithPoolSize set pool size

func WithPoolTimeout

func WithPoolTimeout(poolTimeout time.Duration) Option

WithPoolTimeout set pool timeout

func WithPwd

func WithPwd(pwd string) Option

WithPwd set pwd

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) Option

WithReadTimeout set readTimeout

func WithSentinel

func WithSentinel(sc SentinelConfig) Option

WithSentinel use redis sentinel

func WithTLSConfig

func WithTLSConfig(tlsConfig *tls.Config) Option

WithTLSConfig set TLSConfig

func WithUsername

func WithUsername(username string) Option

WithUsername set username

func WithWaitTime

func WithWaitTime(t time.Duration) Option

WithWaitTime set wait timeout

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) Option

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
}

func NewRedisPool added in v1.15.2

func NewRedisPool(ctx context.Context, config *Config, statis plugin.Statis, opts ...Option) Pool

NewRedisPool init a redis connection pool instance

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.

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task ckv任务请求结构体

func (Task) String

func (t Task) String() string

String

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL