gredigo

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2022 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRedisConnectionNotFound redis connection not found
	ErrRedisConnectionNotFound = errors.New("redis connection not found")

	// ErrRedisConnectionInvalid redis connection invalid
	ErrRedisConnectionInvalid = errors.New("redis connection invalid")
)
View Source
var RedisPoolList = map[string]*redis.Pool{}

RedisPoolList 存放连接池信息

Functions

func AddRedisPool

func AddRedisPool(name string, conf *RedisConf)

AddRedisPool 添加新的redis连接池

func CloseAllPool added in v1.3.6

func CloseAllPool() map[string]error

CloseAllPool 释放所有的连接池,返回map[name]error

func ClosePoolByName added in v1.3.6

func ClosePoolByName(name string) error

ClosePoolByName 通过name释放连接池

func GetRedisClient

func GetRedisClient(name string, timeoutCtx ...context.Context) redis.Conn

GetRedisClient 通过指定name获取池子中的redis连接句柄

func GetRedisClientWithTimeout added in v1.3.4

func GetRedisClientWithTimeout(name string, ctx context.Context) redis.ConnWithTimeout

GetRedisClientWithTimeout return redis.ConnWithTimeout you can use DoWithTimeout method.

func NewRedisPool

func NewRedisPool(conf *RedisConf) *redis.Pool

NewRedisPool 创建redis pool连接池 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.

TestOnBorrow is an optional application supplied function for checking the health of an idle connection before the connection is used again by the application. Argument t is the time that the connection was returned to the pool. If the function returns an error, then the connection is closed.

Types

type ErrorConn added in v1.3.4

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

ErrorConn error connection impl redis.Conn and redis.ConnWithTimeout

func (ErrorConn) Close added in v1.3.4

func (ec ErrorConn) Close() error

func (ErrorConn) Do added in v1.3.4

func (ec ErrorConn) Do(string, ...interface{}) (interface{}, error)

func (ErrorConn) DoWithTimeout added in v1.3.4

func (ec ErrorConn) DoWithTimeout(time.Duration, string, ...interface{}) (interface{}, error)

func (ErrorConn) Err added in v1.3.4

func (ec ErrorConn) Err() error

func (ErrorConn) Flush added in v1.3.4

func (ec ErrorConn) Flush() error

func (ErrorConn) Receive added in v1.3.4

func (ec ErrorConn) Receive() (interface{}, error)

func (ErrorConn) ReceiveWithTimeout added in v1.3.4

func (ec ErrorConn) ReceiveWithTimeout(time.Duration) (interface{}, error)

func (ErrorConn) Send added in v1.3.4

func (ec ErrorConn) Send(string, ...interface{}) error

type RedisConf

type RedisConf struct {
	Host     string
	Port     int
	Password string
	Database int

	// MaxIdle Maximum number of idle connections in the pool.
	MaxIdle int // 空闲连接的最大数量

	// MaxActive 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 // 最大激活数量

	ConnectTimeout int // 连接超时,单位s
	ReadTimeout    int // 读取超时,单位s
	WriteTimeout   int // 写入超时,单位s

	// Close 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 int // 空闲连接超时,单位s

	// Close connections older than this duration. If the value is zero, then
	// the pool does not close connections based on age.
	MaxConnLifetime int // 连接最大生命周期,单位s,默认1800s
}

RedisConf redis连接信息 假如redigo要实现集群参考: redis-go-cluster

func (*RedisConf) SetRedisPool

func (r *RedisConf) SetRedisPool(name string)

SetRedisPool 设置redis连接池

Jump to

Keyboard shortcuts

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