Documentation
¶
Index ¶
- Variables
- func ArgsToInterfaces(args []string) (interfaces []interface{})
- func MakeKey(elems ...string) (key string)
- type API
- type APPEND
- type BITCOUNT
- type BITFIELD
- type BITOP
- type BITPOS
- type COPY
- type Connecter
- type DECR
- type DECRBY
- type DEL
- type DUMP
- type EXISTS
- type EXPIRE
- type EXPIREAT
- type EXPIRETIME
- type ErrUnlock
- type GET
- type GETBIT
- type GETDEL
- type GETEX
- type GETRANGE
- type GoRedisV8
- func (r GoRedisV8) DoArrayIntegerReply(ctx context.Context, args []string) (reply []OptionInt64, err error)
- func (r GoRedisV8) DoArrayStringReply(ctx context.Context, args []string) (reply []OptionString, err error)
- func (r GoRedisV8) DoIntegerReply(ctx context.Context, args []string) (reply int64, isNil bool, err error)
- func (r GoRedisV8) DoIntegerReplyWithoutNil(ctx context.Context, args []string) (reply int64, err error)
- func (r GoRedisV8) DoStringReply(ctx context.Context, args []string) (reply string, isNil bool, err error)
- func (r GoRedisV8) DoStringReplyWithoutNil(ctx context.Context, args []string) (reply string, err error)
- func (r GoRedisV8) Eval(ctx context.Context, data Script) (reply Reply, isNil bool, err error)
- func (r GoRedisV8) EvalWithoutNil(ctx context.Context, data Script) (reply Reply, err error)
- type HDEL
- type INCR
- type INCRBY
- type INCRBYFLOAT
- type IncrLimiter
- type KEYS
- type KeyValue
- type MGET
- type MSET
- type MSETNX
- type Mutex
- type OptionDuration
- type OptionInt64
- type OptionString
- type OptionUint8
- type OptionUint32
- type OptionUint64
- type PEXPIRE
- type PTTL
- type Reply
- type ResultTTL
- type Retry
- type SET
- type SETBIT
- type SETRANGE
- type STRLEN
- type Script
- type SetLimiter
- type Trigger
- type UNLINK
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrSetForgetTimeToLive = errors.New("goclub/redis: SET maybe you forget set field Expire or ExpireAt or KeepTTL or NeverExpire")
Functions ¶
func ArgsToInterfaces ¶
func ArgsToInterfaces(args []string) (interfaces []interface{})
Types ¶
type API ¶
type API struct {
// strings
Append APPEND
BitCount BITCOUNT
BitField BITFIELD
BitOp BITOP
BitPos BITPOS
Decr DECR
DecrBy DECRBY
Get GET
GetBit GETBIT
GetDel GETDEL
GetEx GETEX
GetRange GETRANGE
// GETSET: Please use SET (GETSET有清空TTL的"隐患")
Incr INCR
IncrBy INCRBY
IncrByFloat INCRBYFLOAT
MGet MGET
MSet MSET
MSetNX MSETNX
// PSETEX: Please use SET
Set SET
SetBit SETBIT
SetRange SETRANGE
// STRALGO TODO
StrLen STRLEN
// keys
Copy COPY
Del DEL
Unlink UNLINK
Dump DUMP
Exists EXISTS
Expire EXPIRE
ExpireAt EXPIREAT // @needtest
ExpireTime EXPIRETIME // @needtest
Keys KEYS
PExpire PEXPIRE
// PEXPIREAT
// PEXPIRETIME
PTTL PTTL
// RENAME
// RENAMENX
// RESTORE
// SORT
// SORT_RO
// TOUCH
// TTL
// TYPE
// UNLINK
// WAIT
// SCAN
HDEL HDEL
}
type BITCOUNT ¶
type BITCOUNT struct {
Key string
// start and end offset unit byte (8bit)
StartByte OptionInt64
EndByte OptionInt64
}
type BITPOS ¶
type BITPOS struct {
Key string
Bit uint8
Start OptionUint64
End OptionUint64
}
type Connecter ¶
type Connecter interface {
DoStringReply(ctx context.Context, args []string) (reply string, isNil bool, err error)
DoStringReplyWithoutNil(ctx context.Context, args []string) (reply string, err error)
DoIntegerReply(ctx context.Context, args []string) (reply int64, isNil bool, err error)
DoIntegerReplyWithoutNil(ctx context.Context, args []string) (reply int64, err error)
DoArrayIntegerReply(ctx context.Context, args []string) (reply []OptionInt64, err error)
DoArrayStringReply(ctx context.Context, args []string) (reply []OptionString, err error)
Eval(ctx context.Context, script Script) (reply Reply, isNil bool, err error)
EvalWithoutNil(ctx context.Context, script Script) (reply Reply, err error)
}
Connecter RESP
type DEL ¶
type EXPIRETIME ¶
type EXPIRETIME struct {
Key string
}
type ErrUnlock ¶
func AsErrUnlock ¶
func (*ErrUnlock) Error ¶
自定义错误的 Error 方法一定要加 (*Errxxx) 原因:https://github.com/goclub/error
type GoRedisV8 ¶
type GoRedisV8 struct {
Core redis.UniversalClient
}
func NewGoRedisV8 ¶
func NewGoRedisV8(goredisV8Client redis.UniversalClient) GoRedisV8
func (GoRedisV8) DoArrayIntegerReply ¶
func (GoRedisV8) DoArrayStringReply ¶
func (GoRedisV8) DoIntegerReply ¶
func (GoRedisV8) DoIntegerReplyWithoutNil ¶
func (GoRedisV8) DoStringReply ¶
func (GoRedisV8) DoStringReplyWithoutNil ¶
type INCRBYFLOAT ¶
type IncrLimiter ¶
type IncrLimiter struct {
Key string `note:"key" eg:"mq_requeue:{messageID}"`
Expire time.Duration `note:"有效期" eg:"time.Minute"`
Maximum uint64 `note:"最大限制" eg:"3"`
Increment uint64 `note:"递增值" default:"1"`
}
IncrLimiter 递增限制器 eg:消息队列:重新入队:消息ID作为key在1分钟内只能递增3次.三次内返回的Limited为false,超过三次为true
type Mutex ¶
type OptionDuration ¶
func NewOptionDuration ¶
func NewOptionDuration(duration time.Duration) OptionDuration
type OptionInt64 ¶
func NewOptionInt64 ¶
func NewOptionInt64(i int64) OptionInt64
type OptionString ¶
func NewOptionString ¶
func NewOptionString(s string) OptionString
type OptionUint8 ¶
func NewOptionUint8 ¶
func NewOptionUint8(i uint8) OptionUint8
type OptionUint32 ¶
func NewOptionUint32 ¶
func NewOptionUint32(i uint32) OptionUint32
type OptionUint64 ¶
func NewOptionUint64 ¶
func NewOptionUint64(i uint64) OptionUint64
type Reply ¶
type Reply struct {
Value interface{}
}
func (Reply) Int64Slice ¶
func (r Reply) Int64Slice() (int64Slice []OptionInt64, err error)
func (Reply) StringSlice ¶
func (r Reply) StringSlice() (stringSlice []OptionString, err error)
func (r Reply) InterfaceSlice() (interfaceSlice []interface{}, err error) {
switch value := r.Value.(type) {
case []interface{}:
return value, nil
default:
return nil, fmt.Errorf("redis: unexpected type(%T) value(%+v) convert []interface", value, value)
}
}
type SET ¶
type SetLimiter ¶
type SetLimiter struct {
Key string `eg:"free_trial:2022-01-01:{userID}"`
Member string `eg:"{chapterID}"`
Expire time.Duration `note:"有效期" eg:"time.Hour*24"`
Maximum uint64 `note:"最大限制" eg:"3"`
}
SetLimiter 集合限制器 使用场景: 限制用户每天只能试读3个章节(如果不允许一天内反复试读相同章节则可以使用 IncrLimiter )
type Trigger ¶
type Trigger struct {
Namespace string `note:"命名空间" eg:"alarm_login_fail:user:1"`
Interval time.Duration `note:"持续多久"`
Threshold uint64 `note:"累计多少次"`
Frequency time.Duration `note:"多久最多只触发一次 建议与Interval相同"`
}
Trigger 触发器 每5分钟出现3次则触发,但是10分钟内只触发一次
func exmaple () {
triggered, err := Trigger{
Namespace: "pay_fail_alarm",
Interval: time.Minute*5,
Threshold: 3,
Frequency: time.Minute*5,
}.Do(ctx, client) ; if err != nil {
return
}
if triggered {
// do some
}
}
Click to show internal directories.
Click to hide internal directories.
