gf: github.com/gogf/gf/g/database/gredis Index | Files

package gredis

import "github.com/gogf/gf/g/database/gredis"

Package gredis provides convenient client for redis server.

Redis Client.

Redis Commands Official: https://redis.io/commands

Redis Chinese Documentation: http://redisdoc.com/

Index

Package Files

gredis.go gredis_config.go gredis_conn.go

Constants

const (
    // Default configuration group name.
    DEFAULT_GROUP_NAME = "default"
)

func ClearConfig Uses

func ClearConfig()

ClearConfig removes all configurations and instances of redis.

func RemoveConfig Uses

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 Uses

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.

type Config Uses

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 GetConfig Uses

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

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

type Conn Uses

type Conn struct {
    redis.Conn
}

Redis connection.

func (*Conn) DoVar Uses

func (c *Conn) DoVar(command string, args ...interface{}) (*gvar.Var, error)

DoVar returns value from Do as gvar.Var.

func (*Conn) ReceiveVar Uses

func (c *Conn) ReceiveVar() (*gvar.Var, error)

ReceiveVar receives a single reply as gvar.Var from the Redis server.

type PoolStats Uses

type PoolStats struct {
    redis.PoolStats
}

Pool statistics.

type Redis Uses

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

Redis client.

func Instance Uses

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, it returns a redis instance with default group.

func New Uses

func New(config Config) *Redis

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

func (*Redis) Close Uses

func (r *Redis) Close() error

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 Uses

func (r *Redis) Conn() *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 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. It does not really "close" the connection, but drop it back to the connection pool.

func (*Redis) DoVar Uses

func (r *Redis) DoVar(command string, args ...interface{}) (*gvar.Var, error)

DoVar returns value from Do as gvar.Var.

func (*Redis) GetConn Uses

func (r *Redis) GetConn() *Conn

Alias of Conn, see Conn.

func (*Redis) Send Uses

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

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

func (*Redis) SetIdleTimeout Uses

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

SetIdleTimeout sets the IdleTimeout attribute of the connection pool.

func (*Redis) SetMaxActive Uses

func (r *Redis) SetMaxActive(value int)

SetMaxActive sets the MaxActive attribute of the connection pool.

func (*Redis) SetMaxConnLifetime Uses

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

SetMaxConnLifetime sets the MaxConnLifetime attribute of the connection pool.

func (*Redis) SetMaxIdle Uses

func (r *Redis) SetMaxIdle(value int)

SetMaxIdle sets the MaxIdle attribute of the connection pool.

func (*Redis) Stats Uses

func (r *Redis) Stats() *PoolStats

Stats returns pool's statistics.

Package gredis imports 5 packages (graph) and is imported by 4 packages. Updated 2019-07-15. Refresh now. Tools for package owners.