Documentation ¶
Index ¶
- Variables
- type Command
- type Options
- type Pool
- func (pool *Pool) Back(conn redis.Conn)
- func (pool *Pool) BatchDo(cmdArr ...*Command) error
- func (pool *Pool) Do(cmd string, args ...any) (any, error)
- func (pool *Pool) DoCommand(cmd *Command) error
- func (pool *Pool) DoScript(script *redis.Script, args ...any) (any, error)
- func (pool *Pool) Get() redis.Conn
- func (pool *Pool) NewScript(source string, keyCount int, autoLoad bool) (*redis.Script, error)
- func (pool *Pool) Start() error
- func (pool *Pool) Stop() error
- func (pool *Pool) Take(ctx context.Context) (redis.Conn, error)
- type PoolOption
- func WithDialOptions(dialOptions ...redis.DialOption) PoolOption
- func WithIdleTimeout(idleTimeout time.Duration) PoolOption
- func WithMaxActive(maxActive int) PoolOption
- func WithMaxConnLifetime(maxConnLifetime time.Duration) PoolOption
- func WithMaxIdle(maxIdle int) PoolOption
- func WithPoolOption(options *Options) PoolOption
- func WithWait(wait bool) PoolOption
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrLessConn = errors.New("less redis conn")
)
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct { Name string Script *redis.Script Args []interface{} ReplyHandler func(err error, reply interface{}, args ...interface{}) ReplyArgs []interface{} }
func NewCommand ¶
func NewCommand(name string, args []interface{}, replyHandler func(err error, reply interface{}, args ...interface{}), replyArgs []interface{}) *Command
NewCommand
@Description: 构建redis命令 @return unc NewCommand(name string, args []interface{},
func NewScriptCommand ¶
func NewScriptCommand(script *redis.Script, args []interface{}, replyHandler func(err error, reply interface{}, args ...interface{}), replyArgs []interface{}) *Command
NewScriptCommand
@Description: 构建redis脚本命令 @return unc NewScriptCommand(script *redis.Script, args []interface{},
type Options ¶
type Options struct { // Maximum number of idle connections in the pool. MaxIdle int // Maximum number of connections allocated by the pool at a given time. // When zero, there is no limit on the number of connections in the pool. MaxActive int // stop connections after remaining idle for this duration. If the value // is zero, then idle connections are not closed. Applications should set // the timeout to a value less than the server's timeout. IdleTimeout time.Duration // If Wait is true and the pool is at the MaxActive limit, then Get() waits // for a connection to be returned to the pool before returning. Wait bool // stop connections older than this duration. If the value is zero, then // the pool does not close connections based on age. MaxConnLifetime time.Duration // specifies options for dialing a Redis server. DialOptions []redis.DialOption }
Options
@Description: options for configuring redis pool
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
func NewPool ¶
func NewPool(dialUrl string, opts ...PoolOption) *Pool
func (*Pool) BatchDo ¶
BatchDo
@Description: 批量执行 Command @receiver pool @param cmdArr @return error
func (*Pool) Do ¶
Do
@Description: 执行redis命令行操作 @receiver pool @param cmd @param args @return interface{} @return error
func (*Pool) DoCommand ¶
DoCommand
@Description: 以 Command 形式执行 @receiver pool @param cmd @return error
func (*Pool) DoScript ¶
DoScript
@Description: 执行lua脚本 @receiver pool @param script @param args @return any @return error
func (*Pool) NewScript ¶
NewScript
@Description: 构建脚本 @receiver pool @param source @param keyCount 这里的keyCount用于决定执行时,前多少参数是KEYS(如KEYS[1],KEYS[2]...),那么之后参数的都是ARGV(如ARGV[1],ARGV[2]...) @param autoLoad 是否自动加载(除非这个脚本大概率不会被执行,否则这里都应该传true) @return *redis.Script @return error
type PoolOption ¶
type PoolOption func(*Options)
PoolOption configures Options
func WithDialOptions ¶
func WithDialOptions(dialOptions ...redis.DialOption) PoolOption
func WithIdleTimeout ¶
func WithIdleTimeout(idleTimeout time.Duration) PoolOption
func WithMaxActive ¶
func WithMaxActive(maxActive int) PoolOption
func WithMaxConnLifetime ¶
func WithMaxConnLifetime(maxConnLifetime time.Duration) PoolOption
func WithMaxIdle ¶
func WithMaxIdle(maxIdle int) PoolOption
func WithPoolOption ¶
func WithPoolOption(options *Options) PoolOption
func WithWait ¶
func WithWait(wait bool) PoolOption
Click to show internal directories.
Click to hide internal directories.