redis

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultGroupName = "default" // Default configuration group name.
	DefaultRedisPort = 6379      // Default redis port configuration if not passed.
	DefaultMaxActive = 50        // Default redis max active connections.
)

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

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.

func SetConfigByStr

func SetConfigByStr(str string, name ...string) error

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 BoolCmd

type BoolCmd = redis.BoolCmd

BoolCmd bool

type Cmd

type Cmd = redis.Cmd

Cmd cmd

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 10)
	MaxActive       int           // Maximum number of connections limit (default is 0 means no limit).
	IdleTimeout     time.Duration // Maximum idle time for connection (default is 10 seconds, not allowed to be set to 0)
	MaxConnLifetime time.Duration // Maximum lifetime of the connection (default is 30 seconds, not allowed to be set to 0)
	ConnectTimeout  time.Duration // Dial connection timeout.
	TLS             bool          // Specifies the config to use when a TLS connection is dialed.
	TLSSkipVerify   bool          // Disables server name verification when connecting over TLS
}

Redis configuration.

func ConfigFromStr

func ConfigFromStr(str string) (config Config, err error)

ConfigFromStr parses and returns config from given str. Eg: host:port[,db,pass?maxIdle=x&maxActive=x&idleTimeout=x&maxConnLifetime=x]

func GetConfig

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

type Conn struct {
	redis.Conn
}

Redis connection.

type Options

type Options = redis.Options

Options 实例化redis client时的参数结构类型

type Redis

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

Redis client.

func Instance

func Instance(name ...string) *Redis

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

func New(config Config) *Redis

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

func NewFromStr

func NewFromStr(str string) (*Redis, error)

NewFromStr creates a redis client object with given configuration string. Redis client maintains a connection pool automatically. The parameter <str> like: 127.0.0.1:6379,0 127.0.0.1:6379,0,password

func (*Redis) AddHMObject

func (db *Redis) AddHMObject(ctx context.Context, entity, key string, value interface{}) error

AddHMObject add an object to a hash map table. It returns an error if occurs.

func (*Redis) AddObject

func (db *Redis) AddObject(ctx context.Context, key string, value interface{}, duration time.Duration) error

AddObject add object for a key. It returns an error if occurs.

func (*Redis) Close

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) DeleteHMObject

func (db *Redis) DeleteHMObject(ctx context.Context, entity, key string) error

DeleteHMObject delete an object from a hash map table. It returns an error if occurs.

func (*Redis) DeleteObject

func (db *Redis) DeleteObject(ctx context.Context, key string) error

DeleteObject delete object from key. It returns an error if occurs.

func (*Redis) GetAllHMObjects

func (db *Redis) GetAllHMObjects(ctx context.Context, entity string) (map[string]string, error)

GetAllHMObjects get all objects from a hash map table. It returns the objects and an error if occurs.

func (*Redis) GetClient

func (r *Redis) GetClient() *redis.Client

func (*Redis) GetHMObject

func (db *Redis) GetHMObject(ctx context.Context, entity, key string, value interface{}) error

GetHMObject get an object from a hash map table. It returns an error if occurs.

func (*Redis) GetObject

func (db *Redis) GetObject(ctx context.Context, key string, value interface{}) error

GetObject get object from key. It returns an error if occurs.

func (*Redis) HMSetEX

func (db *Redis) HMSetEX(key string, fields map[string]interface{}, expiration time.Duration) *Cmd

HMSetEX 执行hmset命令并设置过期时间 单位: 秒

func (*Redis) HMSetMapInfo added in v0.0.11

func (db *Redis) HMSetMapInfo(ctx context.Context, key string, values map[string]interface{}) *BoolCmd

func (*Redis) HScanIter

func (db *Redis) HScanIter(key, match string, count int64) *ScansCmd

HScanIter 获取字典中匹配指定pattern的所有字段

func (*Redis) HSetEX

func (db *Redis) HSetEX(key, field string, value interface{}, expiration time.Duration) *Cmd

HSetEX 执行hset命令并设置过期时间 单位: 秒

func (*Redis) IsReady

func (db *Redis) IsReady(ctx context.Context) bool

IsReady verify the database is ready. It returns true if ready.

func (*Redis) LPushTrim

func (db *Redis) LPushTrim(key string, length int64, values ...interface{}) *Cmd

LPushTrim 从左边向list插入元素,并截取只保留左起length个元素

func (*Redis) RPushTrim

func (db *Redis) RPushTrim(key string, length int64, values ...interface{}) *Cmd

RPushTrim 从右边向list插入元素,并截取只保留右起length个元素

func (*Redis) SScanIter

func (db *Redis) SScanIter(key, match string, count int64) *ScansCmd

SScanIter 获取集合中匹配指定pattern的所有元素 替代sismembers

func (*Redis) ScanIter

func (db *Redis) ScanIter(pattern string, count int64) *ScansCmd

ScanIter 获取匹配指定pattern的所有redis key 替代keys方法

func (*Redis) SetIdleTimeout

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

SetIdleTimeout sets the IdleTimeout attribute of the connection pool. It closes connections after remaining idle for this duration. If the value is zero, then idle connections are not closed. Applications should set the timeout to a value less than the server's timeout.

func (*Redis) SetMaxActive

func (r *Redis) SetMaxActive(value int)

SetMaxActive sets the maximum number of connections allocated by the pool at a given time. When zero, there is no limit on the number of connections in the pool.

Note that if the pool is at the MaxActive limit, then all the operations will wait for a connection to be returned to the pool before returning.

func (*Redis) SetMaxConnLifetime

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

SetMaxConnLifetime sets the MaxConnLifetime attribute of the connection pool. It closes connections older than this duration. If the value is zero, then the pool does not close connections based on age.

func (*Redis) SetMaxIdle

func (r *Redis) SetMaxIdle(value int)

SetMaxIdle sets the maximum number of idle connections in the pool.

func (*Redis) ZAddRemByRank

func (db *Redis) ZAddRemByRank(key string, length int64, members ...Z) *Cmd

ZAddRemByRank 向zset中插入成员并剪切,并截取只保留分数最高的length个成员

func (*Redis) ZScanIter

func (db *Redis) ZScanIter(key, match string, count int64) *ScansCmd

ZScanIter 获取有序集合中匹配指定pattern的所有元素

type ScanCmd

type ScanCmd = redis.ScanCmd

ScanCmd scan cmd

type ScansCmd

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

ScansCmd 定义ScansCmd结构类型, 用于scaniter方法的返回值类型

func NewScansCmd

func NewScansCmd() *ScansCmd

NewScansCmd 实例化

func (*ScansCmd) Result

func (c *ScansCmd) Result() (keys []string, err error)

Result 获取命令执行的结果

func (*ScansCmd) String

func (c *ScansCmd) String() (strSlice []string)

String 以字符串形式展示每个命令的执行结果

func (*ScansCmd) Val

func (c *ScansCmd) Val() (keys []string)

Val 获取命令执行的结果

type Z

type Z = redis.Z

Z z

Jump to

Keyboard shortcuts

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