Documentation ¶
Index ¶
- Constants
- Variables
- func Client(name ...string) *redis.Client
- func Connect(configs map[string]Config)
- func IsNil(err error) bool
- func Open(addr string, options ...func(options *redis.Options)) *redis.Client
- func OpenSentinel(options func(options *redis.FailoverOptions)) *redis.Client
- type Config
- type Redis
- func (b *Redis) Client() *redis.Client
- func (b *Redis) Decr(key string) (int64, error)
- func (b *Redis) DecrBy(key string, value int64) (int64, error)
- func (b *Redis) Del(key string) error
- func (b *Redis) Exists(key string) bool
- func (b *Redis) Expire(key string, expiration time.Duration) (bool, error)
- func (b *Redis) Get(key string) (string, error)
- func (b *Redis) HDel(key string, field string) error
- func (b *Redis) HExists(key string, field string) (bool, error)
- func (b *Redis) HGet(key string, field string) (string, error)
- func (b *Redis) HGetAll(key string, m interface{}) error
- func (b *Redis) HGetAllMap(key string) (map[string]string, error)
- func (b *Redis) HIncrBy(key string, field string, incr int64) (int64, error)
- func (b *Redis) HMSet(key string, m interface{}) error
- func (b *Redis) HSet(key string, field string, value interface{}) error
- func (b *Redis) Incr(key string) (int64, error)
- func (b *Redis) IncrBy(key string, value int64) (int64, error)
- func (b *Redis) LPop(key string) (string, error)
- func (b *Redis) LPush(key string, values ...interface{}) (int64, error)
- func (b *Redis) RPop(key string) (string, error)
- func (b *Redis) RPush(key string, values ...interface{}) (int64, error)
- func (b *Redis) SAdd(key string, members ...interface{}) (int64, error)
- func (b *Redis) Set(key, val string) error
- func (b *Redis) SetEX(key, val string, expiration time.Duration) error
- func (b *Redis) SetNX(key, val string, expiration time.Duration) (bool, error)
- func (b *Redis) TTL(key string) time.Duration
Constants ¶
Variables ¶
View Source
var DecodeHook = func(from reflect.Type, to reflect.Type, v interface{}) (interface{}, error) { if from.Kind() == reflect.String && to.Kind() == reflect.Struct { if to.String() == "time.Time" || to.String() == "*time.Time" { ss := v.(string) t := time.Time{} err := t.UnmarshalBinary([]byte(ss)) if err != nil { var layout = "2006-01-02 15:04:05" if strings.Index(ss, "T") != -1 { layout = time.RFC3339 } t, err = time.ParseInLocation(layout, ss, loc) if err != nil { return nil, err } } return t, nil } vi := reflect.New(to).Interface() if vv, ok := vi.(interface{ Scan(interface{}) error }); ok { err := vv.Scan(v) if err != nil { return nil, err } return vv, nil } } return v, nil }
View Source
var ErrClosed = redis.ErrClosed
View Source
var ErrNoData = errors.New("data is empty")
View Source
var (
ScanTagName = "db"
)
Functions ¶
func Open ¶ added in v1.3.0
func Open(addr string, options ...func(options *redis.Options)) *redis.Client
Open redis client
func OpenSentinel ¶ added in v1.3.0
func OpenSentinel(options func(options *redis.FailoverOptions)) *redis.Client
Open redis client
Types ¶
type Config ¶
type Config struct { Server string Password string DB int MaxRetries int DialTimeout int `json:"dial_timeout" toml:"dial_timeout"` ReadTimeout int `json:"read_timeout" toml:"read_timeout"` WriteTimeout int `json:"write_timeout" toml:"write_timeout"` // sentinel MasterName string `json:"master_name" toml:"master_name"` SentinelAddrs string `json:"sentinel_addrs" toml:"sentinel_addrs"` SentinelUsername string `json:"sentinel_username" toml:"sentinel_username"` SentinelPassword string `json:"sentinel_password" toml:"sentinel_password"` CaCert string `json:"ca_cert" toml:"ca_cert"` CertFile string `json:"cert_file" toml:"cert_file"` CertKey string `json:"cert_key" toml:"cert_key"` }
type Redis ¶ added in v1.3.0
type Redis struct {
// contains filtered or unexported fields
}
func NewRedisWithName ¶ added in v1.3.0
func (*Redis) HGetAllMap ¶ added in v1.3.0
func (*Redis) Set ¶ added in v1.3.0
Set Our specification is that all keys must have an expiration time, so the Set key will expire in one day by default
Click to show internal directories.
Click to hide internal directories.