Documentation ¶
Index ¶
- type Config
- type DefaultLogger
- type ILogger
- type List
- type RBinding
- func (r *RBinding) Del(key string)
- func (r *RBinding) Get(key string, val interface{}) (err error)
- func (r *RBinding) GetSet(key string, val interface{}) (err error)
- func (r *RBinding) List(key string) *List
- func (r *RBinding) LoadOrStorage(key string, val interface{}, ...) error
- func (r *RBinding) MGet(keys ...string) map[string]Value
- func (r *RBinding) Set(key string, val interface{}, expiration time.Duration) (err error)
- func (r *RBinding) SetNX(key string, val interface{}, expiration time.Duration) (rs bool, err error)
- func (r *RBinding) Sets(key string) *Set
- type Redis
- type Set
- func (set *Set) SAdd(members ...interface{})
- func (set *Set) SCard() int64
- func (set *Set) SDiff(container interface{}, diffKeys ...string) interface{}
- func (set *Set) SInter(container interface{}, diffKeys ...string) interface{}
- func (set *Set) SMembers(container interface{}) interface{}
- func (set *Set) SMove(destination string, member interface{}) error
- func (set *Set) SPop(container interface{}, n ...int64) interface{}
- func (set *Set) SRem(members ...interface{}) int64
- func (set *Set) SUnion(container interface{}, diffKeys ...string) interface{}
- type Value
- func (v Value) Bool() (val bool, err error)
- func (v Value) Decode(val interface{}) error
- func (v Value) DecodeValue(val reflect.Value) error
- func (v Value) Float32() (val float32, err error)
- func (v Value) Float64() (val float64, err error)
- func (v Value) Int() (val int, err error)
- func (v Value) Int16() (val int16, err error)
- func (v Value) Int32() (val int32, err error)
- func (v Value) Int64() (val int64, err error)
- func (v Value) Int8() (val int8, err error)
- func (v Value) String() (val string, err error)
- func (v Value) Uint() (val uint, err error)
- func (v Value) Uint16() (val uint16, err error)
- func (v Value) Uint32() (val uint32, err error)
- func (v Value) Uint64() (val uint64, err error)
- func (v Value) Uint8() (val uint8, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { RedisType string `mapstructure:"redis_type"` Network string `mapstructure:"network"` Addr string `mapstructure:"addr"` Password string `mapstructure:"password"` DB int `mapstructure:"db"` Addresses []string `mapstructure:"addresses"` Username string `mapstructure:"username"` SentinelPassword string `mapstructure:"sentinel_password"` MaxRetries int `mapstructure:"max_retries"` MinRetryBackoff string `mapstructure:"min_retry_backoff"` MaxRetryBackoff string `mapstructure:"max_retry_backoff"` DialTimeout string `mapstructure:"dial_timeout"` ReadTimeout string `mapstructure:"read_timeout"` WriteTimeout string `mapstructure:"write_timeout"` PoolSize int `mapstructure:"pool_size"` MinIdleConns int `mapstructure:"min_idle_conns"` MaxConnAge string `mapstructure:"max_conn_age"` PoolTimeout string `mapstructure:"pool_timeout"` IdleTimeout string `mapstructure:"idle_timeout"` IdleCheckFrequency string `mapstructure:"idle_check_frequency"` MaxRedirects int `mapstructure:"max_redirects"` ReadOnly bool `mapstructure:"read_only"` RouteByLatency bool `mapstructure:"route_by_latency"` RouteRandomly bool `mapstructure:"route_randomly"` SlaveOnly bool `mapstructure:"slave_only"` Randomly bool `mapstructure:"randomly"` MasterName string `mapstructure:"master_name"` NewClient func(opt *redis.Options) *redis.Client TLSConfig *tls.Config Dialer func(ctx context.Context, network, addr string) (net.Conn, error) OnConnect func(ctx context.Context, cn *redis.Conn) error Limiter redis.Limiter ClusterSlots func(ctx context.Context) ([]redis.ClusterSlot, error) }
Config redis config
type ILogger ¶
type ILogger interface { Warn(args ...interface{}) Error(args ...interface{}) }
ILogger logger interface
type RBinding ¶
type RBinding struct {
// contains filtered or unexported fields
}
RBinding redis go type binding
Using gob serialization, gob is an operation provided by golang to serialize golang, but interface{} cannot be serialized. For example, you have the following structure, type User struct { Username string FieldAny interface{} }
In fact, when using gob to serialize and deserialize the structure object, an error will be returned, because gob will not automatically help you deal with type problems, but gob provides two methods, gob.Register and gob.RegisterName , These two methods are an operation to register your type to gob global, which is recommended gob.RegisterName Although there is little difference between them, gob.RegisterName internal use sync.Map manage the type of registration, So in fact, it doesn't have to do with where to register and concurrency, So you can choose to register in the controller or anywhere, but remember to register before you use serialization and deserialization, It should be noted that, gob.RegisterName will not accept the problem that the type of registration before and after the same name is different, such as gob.RegisterName("a", A{}); gob.RegisterName("a", B{}), If you do this, will panic
func NewDefaultRBinding ¶
NewDefaultRBinding Gets a default binding for the rbinding operation
func (*RBinding) GetSet ¶
GetSet redis getset
将 val 的写入到 redis , 并将 redis 之前此 key 的值绑定到 val, val 必须是一个引用
func (*RBinding) LoadOrStorage ¶
func (r *RBinding) LoadOrStorage(key string, val interface{}, f func() (expiration time.Duration, data interface{})) error
LoadOrStorage 获取指定key的值,如果值不存在,就执行f方法将返回值存入redis
type Redis ¶
type Redis struct { Config Config // contains filtered or unexported fields }
Redis redis
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set redis set 操作
func (*Set) SDiff ¶
SDiff 返回第一个集合与其他集合之间的差异。
container 是一个结构, 比如这个 set 的值是 string, container 就是 string, 值是struct,container就传struct, 不需要是个引用
func (*Set) SMembers ¶
func (set *Set) SMembers(container interface{}) interface{}
SMembers 返回集合中的所有成员
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value gob 转一些基础类型
func (Value) DecodeValue ¶
DecodeValue 同 Decode, 不过这里的 val 是传入的类型的 reflect.Value