Documentation ¶
Index ¶
- Variables
- func Del(entity RedisEntity, ctx context.Context, keys ...string) error
- func Exists(entity RedisEntity, ctx context.Context, keys ...string) (bool, error)
- func Get(entity RedisEntity, ctx context.Context, key string) (string, error)
- func HDel(entity RedisEntity, ctx context.Context, key string, fields ...string) error
- func HExists(entity RedisEntity, ctx context.Context, key, field string) (bool, error)
- func HGet(entity RedisEntity, ctx context.Context, key, field string) (string, error)
- func HGetAll(entity RedisEntity, ctx context.Context, key string) (map[string]string, error)
- func HKeys(entity RedisEntity, ctx context.Context, key string) ([]string, error)
- func HSet(entity RedisEntity, ctx context.Context, key string, values ...interface{}) error
- func IsValidAddrs(mode int, addrs string) bool
- func IsValidMaster(mode int, master string) bool
- func IsValidMode(mode int) bool
- func Keys(entity RedisEntity, ctx context.Context, pattern string) ([]string, error)
- func Set(entity RedisEntity, ctx context.Context, key string, value interface{}) error
- type ClientConf
- type RedisCluster
- func (r RedisCluster) Close() error
- func (r RedisCluster) Del(ctx context.Context, keys ...string) *redis.IntCmd
- func (r RedisCluster) Exists(ctx context.Context, keys ...string) *redis.IntCmd
- func (r RedisCluster) Get(ctx context.Context, key string) *redis.StringCmd
- func (r RedisCluster) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd
- func (r RedisCluster) HExists(ctx context.Context, key, field string) *redis.BoolCmd
- func (r RedisCluster) HGet(ctx context.Context, key, field string) *redis.StringCmd
- func (r RedisCluster) HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
- func (r RedisCluster) HKeys(ctx context.Context, key string) *redis.StringSliceCmd
- func (r RedisCluster) HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd
- func (r RedisCluster) Keys(ctx context.Context, pattern string) *redis.StringSliceCmd
- func (r RedisCluster) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
- type RedisEntity
- type RedisSentinel
- func (r RedisSentinel) Close() error
- func (r RedisSentinel) Del(ctx context.Context, keys ...string) *redis.IntCmd
- func (r RedisSentinel) Exists(ctx context.Context, keys ...string) *redis.IntCmd
- func (r RedisSentinel) Get(ctx context.Context, key string) *redis.StringCmd
- func (r RedisSentinel) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd
- func (r RedisSentinel) HExists(ctx context.Context, key, field string) *redis.BoolCmd
- func (r RedisSentinel) HGet(ctx context.Context, key, field string) *redis.StringCmd
- func (r RedisSentinel) HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
- func (r RedisSentinel) HKeys(ctx context.Context, key string) *redis.StringSliceCmd
- func (r RedisSentinel) HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd
- func (r RedisSentinel) Keys(ctx context.Context, pattern string) *redis.StringSliceCmd
- func (r RedisSentinel) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
- type RedisSingle
- func (s RedisSingle) Close() error
- func (r RedisSingle) Del(ctx context.Context, keys ...string) *redis.IntCmd
- func (r RedisSingle) Exists(ctx context.Context, keys ...string) *redis.IntCmd
- func (r RedisSingle) Get(ctx context.Context, key string) *redis.StringCmd
- func (r RedisSingle) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd
- func (r RedisSingle) HExists(ctx context.Context, key, field string) *redis.BoolCmd
- func (r RedisSingle) HGet(ctx context.Context, key, field string) *redis.StringCmd
- func (r RedisSingle) HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
- func (r RedisSingle) HKeys(ctx context.Context, key string) *redis.StringSliceCmd
- func (r RedisSingle) HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd
- func (r RedisSingle) Keys(ctx context.Context, pattern string) *redis.StringSliceCmd
- func (s RedisSingle) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
Constants ¶
This section is empty.
Variables ¶
var DefaultMode int = 1
Functions ¶
func HSet ¶
func HSet(entity RedisEntity, ctx context.Context, key string, values ...interface{}) error
HSet set a hash key and the value values's format is one of the folloing: "key1", "value1", "key2", "value2" -- pairs of key,value []string{"key1", "value1", "key2", "value2"} --- slice with pairs of key,value map[string]interface{}{"key1": "value1", "key2": "value2"} --- map
func IsValidAddrs ¶
IsValidAddrs check the address of redis server(or redis sentinel server) is a valid adds this is redis server address and port,like as localhost:6379 when mode is 1(single) these are addresses and ports of redis servers like as localhost:6379;192.168.1.10:6379;x.x.x.x:6379 when mode is 2(cluster) these are addresses and ports of sentinel like as localhost:6379;192.168.1.10:6379;x.x.x.x:6379 when mode is 3(sentinel)
func IsValidMaster ¶
IsValidMode check whether master is a valid hostname
func IsValidMode ¶
IsValidMode check whether mode is a valid redis mode
Types ¶
type ClientConf ¶
type ClientConf struct { // connection mode 1 for single server; 2 for cluster; 3 for sentinel mode Mode int `form:"mode" json:"mode" yaml:"mode" xml:"mode"` // master server name. the value of this field is empty when mode are 1 and 2 Master string `form:"master" json:"master" yaml:"master" xml:"master"` // a string join with semicolon for the addresses of server // this is redis server address and port,like as localhost:6379 when mode is 1 // these are addresses and ports of redis servers like as localhost:6379;192.168.1.10:6379;x.x.x.x:6379 when mode is 2 // these are addresses and ports of sentinel like as localhost:6379;192.168.1.10:6379;x.x.x.x:6379 when mode is 3 Addrs string `form:"addrs" json:"addrs" yaml:"addrs" xml:"addrs"` //redis server username Username string `form:"username" json:"username" yaml:"username" xml:"username"` // redis server password Password string `form:"password" json:"password" yaml:"password" xml:"password"` // sentinel username SentinelUsername string `form:"sentinelUsername" json:"sentinelUsername" yaml:"sentinelUsername" xml:"sentinelUsername"` // sentinel password SentinelPassword string `form:"sentinelPassword" json:"sentinelPassword" yaml:"sentinelPassword" xml:"sentinelPassword"` // db DB int `form:"db" json:"db" yaml:"db" xml:"db"` // tls parameters for agent when agent running as daemon. Tls config.Tls `form:"tls" json:"tls" yaml:"tls" xml:"tls"` }
connection parameters for client.
type RedisCluster ¶
type RedisCluster struct { Client *redis.ClusterClient ClientConf ClientConf }
func (RedisCluster) Close ¶
func (r RedisCluster) Close() error
func (RedisCluster) HGetAll ¶
func (r RedisCluster) HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
func (RedisCluster) HKeys ¶
func (r RedisCluster) HKeys(ctx context.Context, key string) *redis.StringSliceCmd
func (RedisCluster) Keys ¶
func (r RedisCluster) Keys(ctx context.Context, pattern string) *redis.StringSliceCmd
type RedisEntity ¶
type RedisEntity interface { Close() error Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd Get(ctx context.Context, key string) *redis.StringCmd Del(ctx context.Context, keys ...string) *redis.IntCmd Exists(ctx context.Context, keys ...string) *redis.IntCmd HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd HGet(ctx context.Context, key, field string) *redis.StringCmd HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd HExists(ctx context.Context, key, field string) *redis.BoolCmd Keys(ctx context.Context, pattern string) *redis.StringSliceCmd HKeys(ctx context.Context, key string) *redis.StringSliceCmd }
func NewClient ¶
func NewClient(conf ClientConf, workDir string) (RedisEntity, error)
initating a entity according mode, then open a connection to redis server(s) return RedisEntity,nil if successful, otherwise return nil, error
type RedisSentinel ¶
type RedisSentinel struct { Client *redis.Client ClientConf ClientConf }
func (RedisSentinel) Close ¶
func (r RedisSentinel) Close() error
func (RedisSentinel) HGetAll ¶
func (r RedisSentinel) HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
func (RedisSentinel) HKeys ¶
func (r RedisSentinel) HKeys(ctx context.Context, key string) *redis.StringSliceCmd
func (RedisSentinel) Keys ¶
func (r RedisSentinel) Keys(ctx context.Context, pattern string) *redis.StringSliceCmd
type RedisSingle ¶
type RedisSingle struct { Client *redis.Client ClientConf ClientConf }
func (RedisSingle) Close ¶
func (s RedisSingle) Close() error
func (RedisSingle) HGetAll ¶
func (r RedisSingle) HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
func (RedisSingle) HKeys ¶
func (r RedisSingle) HKeys(ctx context.Context, key string) *redis.StringSliceCmd
func (RedisSingle) Keys ¶
func (r RedisSingle) Keys(ctx context.Context, pattern string) *redis.StringSliceCmd