predis

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

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) Back

func (pool *Pool) Back(conn redis.Conn)

Back

@Description: 返还一个连接
@receiver pool
@param conn

func (*Pool) BatchDo

func (pool *Pool) BatchDo(cmdArr ...*Command) error

BatchDo

@Description: 批量执行 Command
@receiver pool
@param cmdArr
@return error

func (*Pool) Do

func (pool *Pool) Do(cmd string, args ...any) (any, error)

Do

@Description: 执行redis命令行操作
@receiver pool
@param cmd
@param args
@return interface{}
@return error

func (*Pool) DoCommand

func (pool *Pool) DoCommand(cmd *Command) error

DoCommand

@Description: 以 Command 形式执行
@receiver pool
@param cmd
@return error

func (*Pool) DoScript

func (pool *Pool) DoScript(script *redis.Script, args ...any) (any, error)

DoScript

@Description: 执行lua脚本 @receiver pool @param script @param args @return any @return error

func (*Pool) Get

func (pool *Pool) Get() redis.Conn

Get

@Description: 获取一个连接
@receiver pool
@return redis.Conn

func (*Pool) NewScript

func (pool *Pool) NewScript(source string, keyCount int, autoLoad bool) (*redis.Script, error)

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

func (*Pool) Start

func (pool *Pool) Start() error

Start

@Description: 开启连接池
@receiver pool
@return error

func (*Pool) Stop

func (pool *Pool) Stop() error

Stop

@Description: 关闭连接池
@receiver pool
@return error

func (*Pool) Take

func (pool *Pool) Take(ctx context.Context) (redis.Conn, error)

Take

@Description: 获取一个连接
@receiver pool
@param ctx
@return redis.Conn
@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

Jump to

Keyboard shortcuts

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