Documentation ¶
Overview ¶
Package gredis provides convenient client for redis server.
Redis Client.
Redis Commands Official: https://redis.io/commands
Redis Chinese Documentation: http://redisdoc.com/
Index ¶
- Constants
- func ClearConfig()
- func RemoveConfig(name ...string)
- func SetConfig(config Config, name ...string)
- func SetConfigByStr(str string, name ...string) error
- type Config
- type Conn
- type PoolStats
- type Redis
- func (r *Redis) Close() error
- func (r *Redis) Conn() *Conn
- func (r *Redis) Do(command string, args ...interface{}) (interface{}, error)
- func (r *Redis) DoVar(command string, args ...interface{}) (*gvar.Var, error)
- func (r *Redis) GetConn() *Conn
- func (r *Redis) SetIdleTimeout(value time.Duration)
- func (r *Redis) SetMaxActive(value int)
- func (r *Redis) SetMaxConnLifetime(value time.Duration)
- func (r *Redis) SetMaxIdle(value int)
- func (r *Redis) Stats() *PoolStats
Constants ¶
const ( DEFAULT_GROUP_NAME = "default" // Default configuration group name. DEFAULT_REDIS_PORT = 6379 // Default redis port configuration if not passed. )
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.
func SetConfig ¶
SetConfig sets the global configuration for specified group. If <name> is not passed, it sets configuration for the default group name.
func SetConfigByStr ¶
SetConfigByStr sets the global configuration for specified group with string. If <name> is not passed, it sets configuration for the default group name.
Types ¶
type Config ¶
type Config struct { Host string Port int Db int Pass string // Password for AUTH. MaxIdle int // Maximum number of connections allowed to be idle (default is 0 means no idle connection) MaxActive int // Maximum number of connections limit (default is 0 means no limit) IdleTimeout time.Duration // Maximum idle time for connection (default is 60 seconds, not allowed to be set to 0) MaxConnLifetime time.Duration // Maximum lifetime of the connection (default is 60 seconds, not allowed to be set to 0) }
Redis configuration.
func ConfigFromStr ¶
ConfigFromStr parses and returns config from given str. Eg: host:port[,db,pass?maxIdle=x&maxActive=x&idleTimeout=x&maxConnLifetime=x]
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis client.
func Instance ¶
Instance returns an instance of redis client with specified group. The <name> param is unnecessary, if <name> is not passed, it returns a redis instance with default configuration group.
func New ¶
New creates a redis client object with given configuration. Redis client maintains a connection pool automatically.
func NewFromStr ¶
NewFromStr creates a redis client object with given configuration string. Redis client maintains a connection pool automatically.
func (*Redis) Close ¶
Close closes the redis connection pool, it will release all connections reserved by this pool. It is not necessary to call Close manually.
func (*Redis) Conn ¶
Conn returns a raw underlying connection object, which expose more methods to communicate with server. **You should call Close function manually if you do not use this connection any further.**
func (*Redis) Do ¶
Do sends a command to the server and returns the received reply. Do automatically get a connection from pool, and close it when the reply received. It does not really "close" the connection, but drops it back to the connection pool.
func (*Redis) SetIdleTimeout ¶
SetIdleTimeout sets the IdleTimeout attribute of the connection pool.
func (*Redis) SetMaxActive ¶
SetMaxActive sets the MaxActive attribute of the connection pool.
func (*Redis) SetMaxConnLifetime ¶
SetMaxConnLifetime sets the MaxConnLifetime attribute of the connection pool.
func (*Redis) SetMaxIdle ¶
SetMaxIdle sets the MaxIdle attribute of the connection pool.