gredis

package
v1.5.23 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package gredis provides convenient client for redis server.

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

Index

Constants

View Source
const (
	// 默认分组名称
	DEFAULT_GROUP_NAME = "default"
)

Variables

This section is empty.

Functions

func ClearConfig

func ClearConfig()

ClearConfig removes all configurations and instances of redis.

清除所有的配置内容。

func RemoveConfig

func RemoveConfig(name ...string)

RemoveConfig removes the global configuration with specified group. If <name> is not passed, it removes configuration of the default group name.

删除指定全局分组配置,name为非必需参数,默认为默认分组名称。

func SetConfig

func SetConfig(config Config, name ...string)

SetConfig sets the global configuration for specified group. If <name> is not passed, it sets configuration for the default group name.

设置全局分组配置,name为非必需参数,默认为默认分组名称。

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服务端但节点连接配置信息

func GetConfig

func GetConfig(name ...string) (config Config, ok bool)

GetConfig returns the global configuration with specified group. If <group> is not passed, it returns configuration of the default group name.

获取指定全局分组配置,group为非必需参数,默认为默认分组名称。

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 Instance

func Instance(name ...string) *Redis

Instance returns an instance of redis client with specified group. The <group> param is unnecessary, if <group> is not passed, return redis instance with default group.

获取指定分组名称的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. It always not necessary to call Close manually.

关闭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