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 Redis
- 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 can be a single address or a comma-separated list of addresses for a cluster.
Address string `json:"address"`
// DB is the database to select after connecting to the server.
DB int `json:"db"`
// User is the user to authenticate with.
User string `json:"user"`
// Password is the password to authenticate with.
Password string `json:"password"`
// MasterName is the name of the master for Sentinel connections.
MasterName string `json:"masterName"`
// MinIdleConns is the minimum number of idle connections.
MinIdleConns int `json:"minIdleConns"`
// MaxIdleConns is the maximum number of idle connections.
MaxIdleConns int `json:"maxIdleConns"`
// MaxRetries is the maximum number of retries before giving up.
MaxRetries int `json:"maxRetries"`
// PoolSize is the maximum number of socket connections.
PoolSize int `json:"poolSize"`
// MinRetryBackoff is the minimum backoff between each retry.
MinRetryBackoff time.Duration `json:"minRetryBackoff"`
// MaxRetryBackoff is the maximum backoff between each retry.
MaxRetryBackoff time.Duration `json:"maxRetryBackoff"`
// DialTimeout is the timeout for establishing new connections.
DialTimeout time.Duration `json:"dialTimeout"`
// ReadTimeout is the timeout for reading.
ReadTimeout time.Duration `json:"readTimeout"`
// WriteTimeout is the timeout for writing.
WriteTimeout time.Duration `json:"writeTimeout"`
// PoolTimeout is the timeout for getting a connection from the pool.
PoolTimeout time.Duration `json:"poolTimeout"`
// ConnMaxIdleTime is the timeout for idle connections.
ConnMaxIdleTime time.Duration `json:"idleTimeout"`
}
Config is the configuration for the Redis client.
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.