Documentation
¶
Index ¶
- Constants
- func RemoveConfig(name ...string)
- func SetConfig(name string, cfg *Config)
- func SetConfigByMap(m map[string]any, name ...string) error
- type Config
- type Hook
- type Redis
- func (r *Redis) AddHook(hook Hook)
- func (r *Redis) Client() redis.UniversalClient
- func (r *Redis) Close() error
- func (r *Redis) DBSize(ctx context.Context) (int64, error)
- func (r *Redis) Del(ctx context.Context, keys ...string) (int64, error)
- func (r *Redis) Exists(ctx context.Context, keys ...string) (int64, error)
- func (r *Redis) Expire(ctx context.Context, key string, expiration time.Duration) (bool, error)
- func (r *Redis) FlushDB(ctx context.Context) error
- func (r *Redis) Get(ctx context.Context, key string) (*mvar.Var, error)
- func (r *Redis) HGet(ctx context.Context, key, field string) (*mvar.Var, error)
- func (r *Redis) HSet(ctx context.Context, key string, fields map[string]interface{}) error
- func (r *Redis) Keys(ctx context.Context, pattern string) ([]string, error)
- func (r *Redis) LPush(ctx context.Context, key string, values ...interface{}) (int64, error)
- func (r *Redis) MGet(ctx context.Context, keys ...string) ([]*mvar.Var, error)
- func (r *Redis) MSet(ctx context.Context, data map[string]interface{}) error
- func (r *Redis) Ping(ctx context.Context) error
- func (r *Redis) RPop(ctx context.Context, key string) (*mvar.Var, error)
- func (r *Redis) SAdd(ctx context.Context, key string, members ...interface{}) (int64, error)
- func (r *Redis) SIsMember(ctx context.Context, key string, member interface{}) (bool, error)
- func (r *Redis) Set(ctx context.Context, key string, value interface{}) error
- func (r *Redis) SetEX(ctx context.Context, key string, value interface{}, duration time.Duration) error
- func (r *Redis) SetNX(ctx context.Context, key string, value interface{}, duration time.Duration) (bool, error)
- func (r *Redis) TTL(ctx context.Context, key string) (time.Duration, error)
- func (r *Redis) ZAdd(ctx context.Context, key string, members ...Z) (int64, error)
- func (r *Redis) ZScore(ctx context.Context, key, member string) (float64, error)
- type Z
Constants ¶
const (
// DefaultName is the default group name for redis instance.
DefaultName = "default"
)
Variables ¶
This section is empty.
Functions ¶
func RemoveConfig ¶
func RemoveConfig(name ...string)
RemoveConfig removes the redis configuration with the specified name.
Types ¶
type Config ¶
type Config struct {
Address string `json:"address"`
DB int `json:"db"`
User string `json:"user"`
Password string `json:"password"`
MasterName string `json:"masterName"` // sentinel master name
MinIdleConns int `json:"minIdleConns"` // minimum number of idle connections
MaxIdleConns int `json:"maxIdleConns"` // maximum number of idle connections
MaxRetries int `json:"maxRetries"` // maximum number of retries before giving up
PoolSize int `json:"poolSize"` // maximum number of socket connections
MinRetryBackoff time.Duration `json:"minRetryBackoff"` // minimum backoff between each retry
MaxRetryBackoff time.Duration `json:"maxRetryBackoff"` // maximum backoff between each retry
DialTimeout time.Duration `json:"dialTimeout"` // timeout for establishing new connections
ReadTimeout time.Duration `json:"readTimeout"` // timeout for reading
WriteTimeout time.Duration `json:"writeTimeout"` // timeout for writing
PoolTimeout time.Duration `json:"poolTimeout"` // timeout for getting a connection from the pool
ConnMaxIdleTime time.Duration `json:"connMaxIdleTime"` // timeout for idle connections
SlowThreshold time.Duration `json:"slowThreshold"` // slow query threshold
Logger *mlog.Logger `json:"-"`
Hooks []Hook `json:"-"`
}
Config is the configuration object for Redis.
func ConfigFromMap ¶
ConfigFromMap parses and returns config from given map.
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis is the main struct for redis operations.
func (*Redis) Client ¶
func (r *Redis) Client() redis.UniversalClient
Client returns the underlying universal client.
func (*Redis) Get ¶
Get retrieves and returns the associated value of given `key`. If the key does not exist the special value nil is returned. An error is returned if the value stored at key is not a string, because GET only handles string values.
func (*Redis) HSet ¶
HSet sets the specified fields to their respective values in the hash stored at key.
func (*Redis) Set ¶
Set sets key to hold the string value. If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.
func (*Redis) SetEX ¶
func (r *Redis) SetEX(ctx context.Context, key string, value interface{}, duration time.Duration) error
SetEx sets key to hold the string value with time.
func (*Redis) SetNX ¶
func (r *Redis) SetNX(ctx context.Context, key string, value interface{}, duration time.Duration) (bool, error)
SetNX sets key to hold string value if key does not exist. In that case, it is equal to SET. When key already holds a value, no operation is performed. SETNX is a an atomic operation.