gf: github.com/johng-cn/gf/g/database/gredis Index | Files

package gredis

import "github.com/johng-cn/gf/g/database/gredis"

Package gredis provides client for redis server.

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

Index

Package Files

gredis.go

type Config Uses

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 Uses

type Conn redis.Conn

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

type PoolStats Uses

type PoolStats struct {
    redis.PoolStats
}

Redis链接池统计信息

type Redis Uses

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

Redis客户端(管理连接池)

func New Uses

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 Uses

func (r *Redis) Close() error

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

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

func (*Redis) Conn Uses

func (r *Redis) Conn() Conn

See GetConn.

func (*Redis) Do Uses

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 Uses

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 Uses

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

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

执行异步命令 - Send

func (*Redis) SetIdleTimeout Uses

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

SetMaxIdle sets the IdleTimeout attribute of the connection pool.

设置属性 - IdleTimeout

func (*Redis) SetMaxActive Uses

func (r *Redis) SetMaxActive(value int)

SetMaxIdle sets the MaxActive attribute of the connection pool.

设置属性 - MaxActive

func (*Redis) SetMaxConnLifetime Uses

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

SetMaxIdle sets the MaxConnLifetime attribute of the connection pool.

设置属性 - MaxConnLifetime

func (*Redis) SetMaxIdle Uses

func (r *Redis) SetMaxIdle(value int)

SetMaxIdle sets the MaxIdle attribute of the connection pool.

设置属性 - MaxIdle

func (*Redis) Stats Uses

func (r *Redis) Stats() *PoolStats

Stats returns pool's statistics.

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

Package gredis imports 4 packages (graph). Updated 2019-03-22. Refresh now. Tools for package owners.