gredis

package
v1.5.21 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package gredis provides client for redis server.

Redis客户端. Redis中文手册文档请参考:http://redisdoc.com/ , Redis官方命令请参考:https://redis.io/commands

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host            string        // 地址
	Port            int           // 端口
	Db              int           // 数据库
	Pass            string        // 授权密码
	MaxIdle         int           // 最大允许空闲存在的连接数(默认为0表示不存在闲置连接)
	MaxActive       int           // 最大连接数量限制(默认为0表示不限制)
	IdleTimeout     time.Duration // 连接最大空闲时间(默认为60秒,不允许设置为0)
	MaxConnLifetime time.Duration // 连接最长存活时间(默认为60秒,不允许设置为0)
}

Redis服务端但节点连接配置信息

type Conn

type Conn redis.Conn

Redis连接对象(连接池中的单个连接)

type PoolStats

type PoolStats struct {
	redis.PoolStats
}

Redis链接池统计信息

type Redis

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

Redis客户端(管理连接池)

func New

func New(config Config) *Redis

New creates a redis client object with given configuration. Redis client maintains a connection pool automatically.

创建redis操作对象.

func (*Redis) Close

func (r *Redis) Close() error

Close closes the redis connection pool, it will release all connections reserved by this pool.

关闭redis管理对象,将会关闭底层的连接池。

func (*Redis) Conn

func (r *Redis) Conn() Conn

See GetConn.

func (*Redis) Do

func (r *Redis) Do(command string, args ...interface{}) (interface{}, error)

Do sends a command to the server and returns the received reply. Do automatically get a connection from pool, and close it when reply received.

执行同步命令,自动从连接池中获取连接,使用完毕后关闭连接(丢回连接池),开发者不用自行Close.

func (*Redis) GetConn

func (r *Redis) GetConn() Conn

GetConn returns a raw connection object, which expose more methods communication with server. **You should call Close function manually if you do not use this connection any further.**

获得一个原生的redis连接对象,用于自定义连接操作, 但是需要注意的是如果不再使用该连接对象时,需要手动Close连接,否则会造成连接数超限。

func (*Redis) Send

func (r *Redis) Send(command string, args ...interface{}) error

Deprecated. Send writes the command to the client's output buffer.

执行异步命令 - Send

func (*Redis) SetIdleTimeout

func (r *Redis) SetIdleTimeout(value time.Duration)

SetMaxIdle sets the IdleTimeout attribute of the connection pool.

设置属性 - IdleTimeout

func (*Redis) SetMaxActive

func (r *Redis) SetMaxActive(value int)

SetMaxIdle sets the MaxActive attribute of the connection pool.

设置属性 - MaxActive

func (*Redis) SetMaxConnLifetime

func (r *Redis) SetMaxConnLifetime(value time.Duration)

SetMaxIdle sets the MaxConnLifetime attribute of the connection pool.

设置属性 - MaxConnLifetime

func (*Redis) SetMaxIdle

func (r *Redis) SetMaxIdle(value int)

SetMaxIdle sets the MaxIdle attribute of the connection pool.

设置属性 - MaxIdle

func (*Redis) Stats

func (r *Redis) Stats() *PoolStats

Stats returns pool's statistics.

获取当前连接池统计信息。

Jump to

Keyboard shortcuts

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