2019-04-08 17:05:15 +08:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
"github.com/go-redis/redis/v7/internal"
|
2019-04-08 17:05:15 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func usePrecise(dur time.Duration) bool {
|
|
|
|
return dur < time.Second || dur%time.Second != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func formatMs(dur time.Duration) int64 {
|
|
|
|
if dur > 0 && dur < time.Millisecond {
|
2020-09-28 05:09:46 +08:00
|
|
|
internal.Logger.Printf(
|
2019-04-08 17:05:15 +08:00
|
|
|
"specified duration is %s, but minimal supported value is %s",
|
|
|
|
dur, time.Millisecond,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return int64(dur / time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
func formatSec(dur time.Duration) int64 {
|
|
|
|
if dur > 0 && dur < time.Second {
|
2020-09-28 05:09:46 +08:00
|
|
|
internal.Logger.Printf(
|
2019-04-08 17:05:15 +08:00
|
|
|
"specified duration is %s, but minimal supported value is %s",
|
|
|
|
dur, time.Second,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return int64(dur / time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
func appendArgs(dst, src []interface{}) []interface{} {
|
|
|
|
if len(src) == 1 {
|
2020-09-28 05:09:46 +08:00
|
|
|
switch v := src[0].(type) {
|
|
|
|
case []string:
|
|
|
|
for _, s := range v {
|
2019-04-08 17:05:15 +08:00
|
|
|
dst = append(dst, s)
|
|
|
|
}
|
|
|
|
return dst
|
2020-09-28 05:09:46 +08:00
|
|
|
case map[string]interface{}:
|
|
|
|
for k, v := range v {
|
|
|
|
dst = append(dst, k, v)
|
|
|
|
}
|
|
|
|
return dst
|
2019-04-08 17:05:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
dst = append(dst, src...)
|
2019-04-08 17:05:15 +08:00
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
|
|
|
type Cmdable interface {
|
|
|
|
Pipeline() Pipeliner
|
|
|
|
Pipelined(fn func(Pipeliner) error) ([]Cmder, error)
|
|
|
|
|
|
|
|
TxPipelined(fn func(Pipeliner) error) ([]Cmder, error)
|
|
|
|
TxPipeline() Pipeliner
|
|
|
|
|
|
|
|
Command() *CommandsInfoCmd
|
|
|
|
ClientGetName() *StringCmd
|
|
|
|
Echo(message interface{}) *StringCmd
|
|
|
|
Ping() *StatusCmd
|
|
|
|
Quit() *StatusCmd
|
|
|
|
Del(keys ...string) *IntCmd
|
|
|
|
Unlink(keys ...string) *IntCmd
|
|
|
|
Dump(key string) *StringCmd
|
|
|
|
Exists(keys ...string) *IntCmd
|
|
|
|
Expire(key string, expiration time.Duration) *BoolCmd
|
|
|
|
ExpireAt(key string, tm time.Time) *BoolCmd
|
|
|
|
Keys(pattern string) *StringSliceCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
Migrate(host, port, key string, db int, timeout time.Duration) *StatusCmd
|
|
|
|
Move(key string, db int) *BoolCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
ObjectRefCount(key string) *IntCmd
|
|
|
|
ObjectEncoding(key string) *StringCmd
|
|
|
|
ObjectIdleTime(key string) *DurationCmd
|
|
|
|
Persist(key string) *BoolCmd
|
|
|
|
PExpire(key string, expiration time.Duration) *BoolCmd
|
|
|
|
PExpireAt(key string, tm time.Time) *BoolCmd
|
|
|
|
PTTL(key string) *DurationCmd
|
|
|
|
RandomKey() *StringCmd
|
|
|
|
Rename(key, newkey string) *StatusCmd
|
|
|
|
RenameNX(key, newkey string) *BoolCmd
|
|
|
|
Restore(key string, ttl time.Duration, value string) *StatusCmd
|
|
|
|
RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd
|
|
|
|
Sort(key string, sort *Sort) *StringSliceCmd
|
|
|
|
SortStore(key, store string, sort *Sort) *IntCmd
|
|
|
|
SortInterfaces(key string, sort *Sort) *SliceCmd
|
|
|
|
Touch(keys ...string) *IntCmd
|
|
|
|
TTL(key string) *DurationCmd
|
|
|
|
Type(key string) *StatusCmd
|
|
|
|
Scan(cursor uint64, match string, count int64) *ScanCmd
|
|
|
|
SScan(key string, cursor uint64, match string, count int64) *ScanCmd
|
|
|
|
HScan(key string, cursor uint64, match string, count int64) *ScanCmd
|
|
|
|
ZScan(key string, cursor uint64, match string, count int64) *ScanCmd
|
|
|
|
Append(key, value string) *IntCmd
|
|
|
|
BitCount(key string, bitCount *BitCount) *IntCmd
|
|
|
|
BitOpAnd(destKey string, keys ...string) *IntCmd
|
|
|
|
BitOpOr(destKey string, keys ...string) *IntCmd
|
|
|
|
BitOpXor(destKey string, keys ...string) *IntCmd
|
|
|
|
BitOpNot(destKey string, key string) *IntCmd
|
|
|
|
BitPos(key string, bit int64, pos ...int64) *IntCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
BitField(key string, args ...interface{}) *IntSliceCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
Decr(key string) *IntCmd
|
|
|
|
DecrBy(key string, decrement int64) *IntCmd
|
|
|
|
Get(key string) *StringCmd
|
|
|
|
GetBit(key string, offset int64) *IntCmd
|
|
|
|
GetRange(key string, start, end int64) *StringCmd
|
|
|
|
GetSet(key string, value interface{}) *StringCmd
|
|
|
|
Incr(key string) *IntCmd
|
|
|
|
IncrBy(key string, value int64) *IntCmd
|
|
|
|
IncrByFloat(key string, value float64) *FloatCmd
|
|
|
|
MGet(keys ...string) *SliceCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
MSet(values ...interface{}) *StatusCmd
|
|
|
|
MSetNX(values ...interface{}) *BoolCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
Set(key string, value interface{}, expiration time.Duration) *StatusCmd
|
|
|
|
SetBit(key string, offset int64, value int) *IntCmd
|
|
|
|
SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd
|
|
|
|
SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd
|
|
|
|
SetRange(key string, offset int64, value string) *IntCmd
|
|
|
|
StrLen(key string) *IntCmd
|
|
|
|
HDel(key string, fields ...string) *IntCmd
|
|
|
|
HExists(key, field string) *BoolCmd
|
|
|
|
HGet(key, field string) *StringCmd
|
|
|
|
HGetAll(key string) *StringStringMapCmd
|
|
|
|
HIncrBy(key, field string, incr int64) *IntCmd
|
|
|
|
HIncrByFloat(key, field string, incr float64) *FloatCmd
|
|
|
|
HKeys(key string) *StringSliceCmd
|
|
|
|
HLen(key string) *IntCmd
|
|
|
|
HMGet(key string, fields ...string) *SliceCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
HSet(key string, values ...interface{}) *IntCmd
|
|
|
|
HMSet(key string, values ...interface{}) *BoolCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
HSetNX(key, field string, value interface{}) *BoolCmd
|
|
|
|
HVals(key string) *StringSliceCmd
|
|
|
|
BLPop(timeout time.Duration, keys ...string) *StringSliceCmd
|
|
|
|
BRPop(timeout time.Duration, keys ...string) *StringSliceCmd
|
|
|
|
BRPopLPush(source, destination string, timeout time.Duration) *StringCmd
|
|
|
|
LIndex(key string, index int64) *StringCmd
|
|
|
|
LInsert(key, op string, pivot, value interface{}) *IntCmd
|
|
|
|
LInsertBefore(key string, pivot, value interface{}) *IntCmd
|
|
|
|
LInsertAfter(key string, pivot, value interface{}) *IntCmd
|
|
|
|
LLen(key string) *IntCmd
|
|
|
|
LPop(key string) *StringCmd
|
|
|
|
LPush(key string, values ...interface{}) *IntCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
LPushX(key string, values ...interface{}) *IntCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
LRange(key string, start, stop int64) *StringSliceCmd
|
|
|
|
LRem(key string, count int64, value interface{}) *IntCmd
|
|
|
|
LSet(key string, index int64, value interface{}) *StatusCmd
|
|
|
|
LTrim(key string, start, stop int64) *StatusCmd
|
|
|
|
RPop(key string) *StringCmd
|
|
|
|
RPopLPush(source, destination string) *StringCmd
|
|
|
|
RPush(key string, values ...interface{}) *IntCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
RPushX(key string, values ...interface{}) *IntCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
SAdd(key string, members ...interface{}) *IntCmd
|
|
|
|
SCard(key string) *IntCmd
|
|
|
|
SDiff(keys ...string) *StringSliceCmd
|
|
|
|
SDiffStore(destination string, keys ...string) *IntCmd
|
|
|
|
SInter(keys ...string) *StringSliceCmd
|
|
|
|
SInterStore(destination string, keys ...string) *IntCmd
|
|
|
|
SIsMember(key string, member interface{}) *BoolCmd
|
|
|
|
SMembers(key string) *StringSliceCmd
|
|
|
|
SMembersMap(key string) *StringStructMapCmd
|
|
|
|
SMove(source, destination string, member interface{}) *BoolCmd
|
|
|
|
SPop(key string) *StringCmd
|
|
|
|
SPopN(key string, count int64) *StringSliceCmd
|
|
|
|
SRandMember(key string) *StringCmd
|
|
|
|
SRandMemberN(key string, count int64) *StringSliceCmd
|
|
|
|
SRem(key string, members ...interface{}) *IntCmd
|
|
|
|
SUnion(keys ...string) *StringSliceCmd
|
|
|
|
SUnionStore(destination string, keys ...string) *IntCmd
|
|
|
|
XAdd(a *XAddArgs) *StringCmd
|
|
|
|
XDel(stream string, ids ...string) *IntCmd
|
|
|
|
XLen(stream string) *IntCmd
|
|
|
|
XRange(stream, start, stop string) *XMessageSliceCmd
|
|
|
|
XRangeN(stream, start, stop string, count int64) *XMessageSliceCmd
|
|
|
|
XRevRange(stream string, start, stop string) *XMessageSliceCmd
|
|
|
|
XRevRangeN(stream string, start, stop string, count int64) *XMessageSliceCmd
|
|
|
|
XRead(a *XReadArgs) *XStreamSliceCmd
|
|
|
|
XReadStreams(streams ...string) *XStreamSliceCmd
|
|
|
|
XGroupCreate(stream, group, start string) *StatusCmd
|
|
|
|
XGroupCreateMkStream(stream, group, start string) *StatusCmd
|
|
|
|
XGroupSetID(stream, group, start string) *StatusCmd
|
|
|
|
XGroupDestroy(stream, group string) *IntCmd
|
|
|
|
XGroupDelConsumer(stream, group, consumer string) *IntCmd
|
|
|
|
XReadGroup(a *XReadGroupArgs) *XStreamSliceCmd
|
|
|
|
XAck(stream, group string, ids ...string) *IntCmd
|
|
|
|
XPending(stream, group string) *XPendingCmd
|
|
|
|
XPendingExt(a *XPendingExtArgs) *XPendingExtCmd
|
|
|
|
XClaim(a *XClaimArgs) *XMessageSliceCmd
|
|
|
|
XClaimJustID(a *XClaimArgs) *StringSliceCmd
|
|
|
|
XTrim(key string, maxLen int64) *IntCmd
|
|
|
|
XTrimApprox(key string, maxLen int64) *IntCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
XInfoGroups(key string) *XInfoGroupsCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
BZPopMax(timeout time.Duration, keys ...string) *ZWithKeyCmd
|
|
|
|
BZPopMin(timeout time.Duration, keys ...string) *ZWithKeyCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
ZAdd(key string, members ...*Z) *IntCmd
|
|
|
|
ZAddNX(key string, members ...*Z) *IntCmd
|
|
|
|
ZAddXX(key string, members ...*Z) *IntCmd
|
|
|
|
ZAddCh(key string, members ...*Z) *IntCmd
|
|
|
|
ZAddNXCh(key string, members ...*Z) *IntCmd
|
|
|
|
ZAddXXCh(key string, members ...*Z) *IntCmd
|
|
|
|
ZIncr(key string, member *Z) *FloatCmd
|
|
|
|
ZIncrNX(key string, member *Z) *FloatCmd
|
|
|
|
ZIncrXX(key string, member *Z) *FloatCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
ZCard(key string) *IntCmd
|
|
|
|
ZCount(key, min, max string) *IntCmd
|
|
|
|
ZLexCount(key, min, max string) *IntCmd
|
|
|
|
ZIncrBy(key string, increment float64, member string) *FloatCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
ZInterStore(destination string, store *ZStore) *IntCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
ZPopMax(key string, count ...int64) *ZSliceCmd
|
|
|
|
ZPopMin(key string, count ...int64) *ZSliceCmd
|
|
|
|
ZRange(key string, start, stop int64) *StringSliceCmd
|
|
|
|
ZRangeWithScores(key string, start, stop int64) *ZSliceCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
ZRangeByScore(key string, opt *ZRangeBy) *StringSliceCmd
|
|
|
|
ZRangeByLex(key string, opt *ZRangeBy) *StringSliceCmd
|
|
|
|
ZRangeByScoreWithScores(key string, opt *ZRangeBy) *ZSliceCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
ZRank(key, member string) *IntCmd
|
|
|
|
ZRem(key string, members ...interface{}) *IntCmd
|
|
|
|
ZRemRangeByRank(key string, start, stop int64) *IntCmd
|
|
|
|
ZRemRangeByScore(key, min, max string) *IntCmd
|
|
|
|
ZRemRangeByLex(key, min, max string) *IntCmd
|
|
|
|
ZRevRange(key string, start, stop int64) *StringSliceCmd
|
|
|
|
ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
ZRevRangeByScore(key string, opt *ZRangeBy) *StringSliceCmd
|
|
|
|
ZRevRangeByLex(key string, opt *ZRangeBy) *StringSliceCmd
|
|
|
|
ZRevRangeByScoreWithScores(key string, opt *ZRangeBy) *ZSliceCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
ZRevRank(key, member string) *IntCmd
|
|
|
|
ZScore(key, member string) *FloatCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
ZUnionStore(dest string, store *ZStore) *IntCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
PFAdd(key string, els ...interface{}) *IntCmd
|
|
|
|
PFCount(keys ...string) *IntCmd
|
|
|
|
PFMerge(dest string, keys ...string) *StatusCmd
|
|
|
|
BgRewriteAOF() *StatusCmd
|
|
|
|
BgSave() *StatusCmd
|
|
|
|
ClientKill(ipPort string) *StatusCmd
|
|
|
|
ClientKillByFilter(keys ...string) *IntCmd
|
|
|
|
ClientList() *StringCmd
|
|
|
|
ClientPause(dur time.Duration) *BoolCmd
|
|
|
|
ClientID() *IntCmd
|
|
|
|
ConfigGet(parameter string) *SliceCmd
|
|
|
|
ConfigResetStat() *StatusCmd
|
|
|
|
ConfigSet(parameter, value string) *StatusCmd
|
|
|
|
ConfigRewrite() *StatusCmd
|
|
|
|
DBSize() *IntCmd
|
|
|
|
FlushAll() *StatusCmd
|
|
|
|
FlushAllAsync() *StatusCmd
|
|
|
|
FlushDB() *StatusCmd
|
|
|
|
FlushDBAsync() *StatusCmd
|
|
|
|
Info(section ...string) *StringCmd
|
|
|
|
LastSave() *IntCmd
|
|
|
|
Save() *StatusCmd
|
|
|
|
Shutdown() *StatusCmd
|
|
|
|
ShutdownSave() *StatusCmd
|
|
|
|
ShutdownNoSave() *StatusCmd
|
|
|
|
SlaveOf(host, port string) *StatusCmd
|
|
|
|
Time() *TimeCmd
|
|
|
|
Eval(script string, keys []string, args ...interface{}) *Cmd
|
|
|
|
EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd
|
|
|
|
ScriptExists(hashes ...string) *BoolSliceCmd
|
|
|
|
ScriptFlush() *StatusCmd
|
|
|
|
ScriptKill() *StatusCmd
|
|
|
|
ScriptLoad(script string) *StringCmd
|
|
|
|
DebugObject(key string) *StringCmd
|
|
|
|
Publish(channel string, message interface{}) *IntCmd
|
|
|
|
PubSubChannels(pattern string) *StringSliceCmd
|
|
|
|
PubSubNumSub(channels ...string) *StringIntMapCmd
|
|
|
|
PubSubNumPat() *IntCmd
|
|
|
|
ClusterSlots() *ClusterSlotsCmd
|
|
|
|
ClusterNodes() *StringCmd
|
|
|
|
ClusterMeet(host, port string) *StatusCmd
|
|
|
|
ClusterForget(nodeID string) *StatusCmd
|
|
|
|
ClusterReplicate(nodeID string) *StatusCmd
|
|
|
|
ClusterResetSoft() *StatusCmd
|
|
|
|
ClusterResetHard() *StatusCmd
|
|
|
|
ClusterInfo() *StringCmd
|
|
|
|
ClusterKeySlot(key string) *IntCmd
|
|
|
|
ClusterGetKeysInSlot(slot int, count int) *StringSliceCmd
|
|
|
|
ClusterCountFailureReports(nodeID string) *IntCmd
|
|
|
|
ClusterCountKeysInSlot(slot int) *IntCmd
|
|
|
|
ClusterDelSlots(slots ...int) *StatusCmd
|
|
|
|
ClusterDelSlotsRange(min, max int) *StatusCmd
|
|
|
|
ClusterSaveConfig() *StatusCmd
|
|
|
|
ClusterSlaves(nodeID string) *StringSliceCmd
|
|
|
|
ClusterFailover() *StatusCmd
|
|
|
|
ClusterAddSlots(slots ...int) *StatusCmd
|
|
|
|
ClusterAddSlotsRange(min, max int) *StatusCmd
|
|
|
|
GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd
|
|
|
|
GeoPos(key string, members ...string) *GeoPosCmd
|
|
|
|
GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
GeoRadiusStore(key string, longitude, latitude float64, query *GeoRadiusQuery) *IntCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
GeoRadiusByMemberStore(key, member string, query *GeoRadiusQuery) *IntCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
GeoDist(key string, member1, member2, unit string) *FloatCmd
|
|
|
|
GeoHash(key string, members ...string) *StringSliceCmd
|
|
|
|
ReadOnly() *StatusCmd
|
|
|
|
ReadWrite() *StatusCmd
|
|
|
|
MemoryUsage(key string, samples ...int) *IntCmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type StatefulCmdable interface {
|
|
|
|
Cmdable
|
|
|
|
Auth(password string) *StatusCmd
|
2020-09-28 05:09:46 +08:00
|
|
|
AuthACL(username, password string) *StatusCmd
|
2019-04-08 17:05:15 +08:00
|
|
|
Select(index int) *StatusCmd
|
|
|
|
SwapDB(index1, index2 int) *StatusCmd
|
|
|
|
ClientSetName(name string) *BoolCmd
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Cmdable = (*Client)(nil)
|
|
|
|
var _ Cmdable = (*Tx)(nil)
|
|
|
|
var _ Cmdable = (*Ring)(nil)
|
|
|
|
var _ Cmdable = (*ClusterClient)(nil)
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
type cmdable func(cmd Cmder) error
|
2019-04-08 17:05:15 +08:00
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
type statefulCmdable func(cmd Cmder) error
|
2019-04-08 17:05:15 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c statefulCmdable) Auth(password string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("auth", password)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform an AUTH command, using the given user and pass.
|
|
|
|
// Should be used to authenticate the current connection with one of the connections defined in the ACL list
|
|
|
|
// when connecting to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
|
|
|
|
func (c statefulCmdable) AuthACL(username, password string) *StatusCmd {
|
|
|
|
cmd := NewStatusCmd("auth", username, password)
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Echo(message interface{}) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("echo", message)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Ping() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("ping")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Wait(numSlaves int, timeout time.Duration) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("wait", numSlaves, int(timeout/time.Millisecond))
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Quit() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c statefulCmdable) Select(index int) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("select", index)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c statefulCmdable) SwapDB(index1, index2 int) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("swapdb", index1, index2)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Command() *CommandsInfoCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewCommandsInfoCmd("command")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Del(keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
|
|
|
args[0] = "del"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Unlink(keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
|
|
|
args[0] = "unlink"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Dump(key string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("dump", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Exists(keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
|
|
|
args[0] = "exists"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Expire(key string, expiration time.Duration) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("expire", key, formatSec(expiration))
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ExpireAt(key string, tm time.Time) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("expireat", key, tm.Unix())
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Keys(pattern string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringSliceCmd("keys", pattern)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Migrate(host, port, key string, db int, timeout time.Duration) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd(
|
|
|
|
"migrate",
|
|
|
|
host,
|
|
|
|
port,
|
|
|
|
key,
|
|
|
|
db,
|
|
|
|
formatMs(timeout),
|
|
|
|
)
|
|
|
|
cmd.setReadTimeout(timeout)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Move(key string, db int) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("move", key, db)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ObjectRefCount(key string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("object", "refcount", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ObjectEncoding(key string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("object", "encoding", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ObjectIdleTime(key string) *DurationCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewDurationCmd(time.Second, "object", "idletime", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Persist(key string) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("persist", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) PExpire(key string, expiration time.Duration) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("pexpire", key, formatMs(expiration))
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) PExpireAt(key string, tm time.Time) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd(
|
|
|
|
"pexpireat",
|
|
|
|
key,
|
|
|
|
tm.UnixNano()/int64(time.Millisecond),
|
|
|
|
)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) PTTL(key string) *DurationCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewDurationCmd(time.Millisecond, "pttl", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) RandomKey() *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("randomkey")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Rename(key, newkey string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("rename", key, newkey)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) RenameNX(key, newkey string) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("renamenx", key, newkey)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Restore(key string, ttl time.Duration, value string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd(
|
|
|
|
"restore",
|
|
|
|
key,
|
|
|
|
formatMs(ttl),
|
|
|
|
value,
|
|
|
|
)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd(
|
|
|
|
"restore",
|
|
|
|
key,
|
|
|
|
formatMs(ttl),
|
|
|
|
value,
|
|
|
|
"replace",
|
|
|
|
)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type Sort struct {
|
|
|
|
By string
|
|
|
|
Offset, Count int64
|
|
|
|
Get []string
|
|
|
|
Order string
|
|
|
|
Alpha bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sort *Sort) args(key string) []interface{} {
|
|
|
|
args := []interface{}{"sort", key}
|
|
|
|
if sort.By != "" {
|
|
|
|
args = append(args, "by", sort.By)
|
|
|
|
}
|
|
|
|
if sort.Offset != 0 || sort.Count != 0 {
|
|
|
|
args = append(args, "limit", sort.Offset, sort.Count)
|
|
|
|
}
|
|
|
|
for _, get := range sort.Get {
|
|
|
|
args = append(args, "get", get)
|
|
|
|
}
|
|
|
|
if sort.Order != "" {
|
|
|
|
args = append(args, sort.Order)
|
|
|
|
}
|
|
|
|
if sort.Alpha {
|
|
|
|
args = append(args, "alpha")
|
|
|
|
}
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Sort(key string, sort *Sort) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringSliceCmd(sort.args(key)...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SortStore(key, store string, sort *Sort) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := sort.args(key)
|
|
|
|
if store != "" {
|
|
|
|
args = append(args, "store", store)
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SortInterfaces(key string, sort *Sort) *SliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewSliceCmd(sort.args(key)...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Touch(keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, len(keys)+1)
|
|
|
|
args[0] = "touch"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[i+1] = key
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) TTL(key string) *DurationCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewDurationCmd(time.Second, "ttl", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Type(key string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("type", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Scan(cursor uint64, match string, count int64) *ScanCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"scan", cursor}
|
|
|
|
if match != "" {
|
|
|
|
args = append(args, "match", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
|
|
|
args = append(args, "count", count)
|
|
|
|
}
|
2020-09-28 05:09:46 +08:00
|
|
|
cmd := NewScanCmd(c, args...)
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SScan(key string, cursor uint64, match string, count int64) *ScanCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"sscan", key, cursor}
|
|
|
|
if match != "" {
|
|
|
|
args = append(args, "match", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
|
|
|
args = append(args, "count", count)
|
|
|
|
}
|
2020-09-28 05:09:46 +08:00
|
|
|
cmd := NewScanCmd(c, args...)
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) HScan(key string, cursor uint64, match string, count int64) *ScanCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"hscan", key, cursor}
|
|
|
|
if match != "" {
|
|
|
|
args = append(args, "match", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
|
|
|
args = append(args, "count", count)
|
|
|
|
}
|
2020-09-28 05:09:46 +08:00
|
|
|
cmd := NewScanCmd(c, args...)
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZScan(key string, cursor uint64, match string, count int64) *ScanCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"zscan", key, cursor}
|
|
|
|
if match != "" {
|
|
|
|
args = append(args, "match", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
|
|
|
args = append(args, "count", count)
|
|
|
|
}
|
2020-09-28 05:09:46 +08:00
|
|
|
cmd := NewScanCmd(c, args...)
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Append(key, value string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("append", key, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type BitCount struct {
|
|
|
|
Start, End int64
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BitCount(key string, bitCount *BitCount) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"bitcount", key}
|
|
|
|
if bitCount != nil {
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
bitCount.Start,
|
|
|
|
bitCount.End,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) bitOp(op, destKey string, keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 3+len(keys))
|
|
|
|
args[0] = "bitop"
|
|
|
|
args[1] = op
|
|
|
|
args[2] = destKey
|
|
|
|
for i, key := range keys {
|
|
|
|
args[3+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BitOpAnd(destKey string, keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.bitOp("and", destKey, keys...)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BitOpOr(destKey string, keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.bitOp("or", destKey, keys...)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BitOpXor(destKey string, keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.bitOp("xor", destKey, keys...)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BitOpNot(destKey string, key string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.bitOp("not", destKey, key)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BitPos(key string, bit int64, pos ...int64) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 3+len(pos))
|
|
|
|
args[0] = "bitpos"
|
|
|
|
args[1] = key
|
|
|
|
args[2] = bit
|
|
|
|
switch len(pos) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
args[3] = pos[0]
|
|
|
|
case 2:
|
|
|
|
args[3] = pos[0]
|
|
|
|
args[4] = pos[1]
|
|
|
|
default:
|
|
|
|
panic("too many arguments")
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c cmdable) BitField(key string, args ...interface{}) *IntSliceCmd {
|
|
|
|
a := make([]interface{}, 0, 2+len(args))
|
|
|
|
a = append(a, "bitfield")
|
|
|
|
a = append(a, key)
|
|
|
|
a = append(a, args...)
|
|
|
|
cmd := NewIntSliceCmd(a...)
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Decr(key string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("decr", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) DecrBy(key string, decrement int64) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("decrby", key, decrement)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `GET key` command. It returns redis.Nil error when key does not exist.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Get(key string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("get", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) GetBit(key string, offset int64) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("getbit", key, offset)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) GetRange(key string, start, end int64) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("getrange", key, start, end)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) GetSet(key string, value interface{}) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("getset", key, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Incr(key string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("incr", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) IncrBy(key string, value int64) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("incrby", key, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) IncrByFloat(key string, value float64) *FloatCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewFloatCmd("incrbyfloat", key, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) MGet(keys ...string) *SliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
|
|
|
args[0] = "mget"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
// MSet is like Set but accepts multiple values:
|
|
|
|
// - MSet("key1", "value1", "key2", "value2")
|
|
|
|
// - MSet([]string{"key1", "value1", "key2", "value2"})
|
|
|
|
// - MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})
|
|
|
|
func (c cmdable) MSet(values ...interface{}) *StatusCmd {
|
|
|
|
args := make([]interface{}, 1, 1+len(values))
|
2019-04-08 17:05:15 +08:00
|
|
|
args[0] = "mset"
|
2020-09-28 05:09:46 +08:00
|
|
|
args = appendArgs(args, values)
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
// MSetNX is like SetNX but accepts multiple values:
|
|
|
|
// - MSetNX("key1", "value1", "key2", "value2")
|
|
|
|
// - MSetNX([]string{"key1", "value1", "key2", "value2"})
|
|
|
|
// - MSetNX(map[string]interface{}{"key1": "value1", "key2": "value2"})
|
|
|
|
func (c cmdable) MSetNX(values ...interface{}) *BoolCmd {
|
|
|
|
args := make([]interface{}, 1, 1+len(values))
|
2019-04-08 17:05:15 +08:00
|
|
|
args[0] = "msetnx"
|
2020-09-28 05:09:46 +08:00
|
|
|
args = appendArgs(args, values)
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `SET key value [expiration]` command.
|
|
|
|
//
|
|
|
|
// Use expiration for `SETEX`-like behavior.
|
|
|
|
// Zero expiration means the key has no expiration time.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd {
|
|
|
|
args := make([]interface{}, 3, 5)
|
2019-04-08 17:05:15 +08:00
|
|
|
args[0] = "set"
|
|
|
|
args[1] = key
|
|
|
|
args[2] = value
|
|
|
|
if expiration > 0 {
|
|
|
|
if usePrecise(expiration) {
|
|
|
|
args = append(args, "px", formatMs(expiration))
|
|
|
|
} else {
|
|
|
|
args = append(args, "ex", formatSec(expiration))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd := NewStatusCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SetBit(key string, offset int64, value int) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd(
|
|
|
|
"setbit",
|
|
|
|
key,
|
|
|
|
offset,
|
|
|
|
value,
|
|
|
|
)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `SET key value [expiration] NX` command.
|
|
|
|
//
|
|
|
|
// Zero expiration means the key has no expiration time.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
var cmd *BoolCmd
|
|
|
|
if expiration == 0 {
|
|
|
|
// Use old `SETNX` to support old Redis versions.
|
|
|
|
cmd = NewBoolCmd("setnx", key, value)
|
|
|
|
} else {
|
|
|
|
if usePrecise(expiration) {
|
|
|
|
cmd = NewBoolCmd("set", key, value, "px", formatMs(expiration), "nx")
|
|
|
|
} else {
|
|
|
|
cmd = NewBoolCmd("set", key, value, "ex", formatSec(expiration), "nx")
|
|
|
|
}
|
|
|
|
}
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `SET key value [expiration] XX` command.
|
|
|
|
//
|
|
|
|
// Zero expiration means the key has no expiration time.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
var cmd *BoolCmd
|
|
|
|
if expiration == 0 {
|
|
|
|
cmd = NewBoolCmd("set", key, value, "xx")
|
|
|
|
} else {
|
|
|
|
if usePrecise(expiration) {
|
|
|
|
cmd = NewBoolCmd("set", key, value, "px", formatMs(expiration), "xx")
|
|
|
|
} else {
|
|
|
|
cmd = NewBoolCmd("set", key, value, "ex", formatSec(expiration), "xx")
|
|
|
|
}
|
|
|
|
}
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SetRange(key string, offset int64, value string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("setrange", key, offset, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) StrLen(key string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("strlen", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) HDel(key string, fields ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(fields))
|
|
|
|
args[0] = "hdel"
|
|
|
|
args[1] = key
|
|
|
|
for i, field := range fields {
|
|
|
|
args[2+i] = field
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) HExists(key, field string) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("hexists", key, field)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) HGet(key, field string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("hget", key, field)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) HGetAll(key string) *StringStringMapCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringStringMapCmd("hgetall", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) HIncrBy(key, field string, incr int64) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("hincrby", key, field, incr)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) HIncrByFloat(key, field string, incr float64) *FloatCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewFloatCmd("hincrbyfloat", key, field, incr)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) HKeys(key string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringSliceCmd("hkeys", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) HLen(key string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("hlen", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
// HMGet returns the values for the specified fields in the hash stored at key.
|
|
|
|
// It returns an interface{} to distinguish between empty string and nil value.
|
|
|
|
func (c cmdable) HMGet(key string, fields ...string) *SliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(fields))
|
|
|
|
args[0] = "hmget"
|
|
|
|
args[1] = key
|
|
|
|
for i, field := range fields {
|
|
|
|
args[2+i] = field
|
|
|
|
}
|
|
|
|
cmd := NewSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
// HSet accepts values in following formats:
|
|
|
|
// - HMSet("myhash", "key1", "value1", "key2", "value2")
|
|
|
|
// - HMSet("myhash", []string{"key1", "value1", "key2", "value2"})
|
|
|
|
// - HMSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})
|
|
|
|
//
|
|
|
|
// Note that it requires Redis v4 for multiple field/value pairs support.
|
|
|
|
func (c cmdable) HSet(key string, values ...interface{}) *IntCmd {
|
|
|
|
args := make([]interface{}, 2, 2+len(values))
|
|
|
|
args[0] = "hset"
|
2019-04-08 17:05:15 +08:00
|
|
|
args[1] = key
|
2020-09-28 05:09:46 +08:00
|
|
|
args = appendArgs(args, values)
|
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
// HMSet is a deprecated version of HSet left for compatibility with Redis 3.
|
|
|
|
func (c cmdable) HMSet(key string, values ...interface{}) *BoolCmd {
|
|
|
|
args := make([]interface{}, 2, 2+len(values))
|
|
|
|
args[0] = "hmset"
|
|
|
|
args[1] = key
|
|
|
|
args = appendArgs(args, values)
|
|
|
|
cmd := NewBoolCmd(args...)
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) HSetNX(key, field string, value interface{}) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("hsetnx", key, field, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) HVals(key string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringSliceCmd("hvals", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys)+1)
|
|
|
|
args[0] = "blpop"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
args[len(args)-1] = formatSec(timeout)
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
|
|
|
cmd.setReadTimeout(timeout)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys)+1)
|
|
|
|
args[0] = "brpop"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
args[len(keys)+1] = formatSec(timeout)
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
|
|
|
cmd.setReadTimeout(timeout)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BRPopLPush(source, destination string, timeout time.Duration) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd(
|
|
|
|
"brpoplpush",
|
|
|
|
source,
|
|
|
|
destination,
|
|
|
|
formatSec(timeout),
|
|
|
|
)
|
|
|
|
cmd.setReadTimeout(timeout)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LIndex(key string, index int64) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("lindex", key, index)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LInsert(key, op string, pivot, value interface{}) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("linsert", key, op, pivot, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LInsertBefore(key string, pivot, value interface{}) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("linsert", key, "before", pivot, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LInsertAfter(key string, pivot, value interface{}) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("linsert", key, "after", pivot, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LLen(key string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("llen", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LPop(key string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("lpop", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LPush(key string, values ...interface{}) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2, 2+len(values))
|
|
|
|
args[0] = "lpush"
|
|
|
|
args[1] = key
|
|
|
|
args = appendArgs(args, values)
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LPushX(key string, values ...interface{}) *IntCmd {
|
|
|
|
args := make([]interface{}, 2, 2+len(values))
|
|
|
|
args[0] = "lpushx"
|
|
|
|
args[1] = key
|
|
|
|
args = appendArgs(args, values)
|
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LRange(key string, start, stop int64) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringSliceCmd(
|
|
|
|
"lrange",
|
|
|
|
key,
|
|
|
|
start,
|
|
|
|
stop,
|
|
|
|
)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LRem(key string, count int64, value interface{}) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("lrem", key, count, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LSet(key string, index int64, value interface{}) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("lset", key, index, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LTrim(key string, start, stop int64) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd(
|
|
|
|
"ltrim",
|
|
|
|
key,
|
|
|
|
start,
|
|
|
|
stop,
|
|
|
|
)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) RPop(key string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("rpop", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) RPopLPush(source, destination string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("rpoplpush", source, destination)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) RPush(key string, values ...interface{}) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2, 2+len(values))
|
|
|
|
args[0] = "rpush"
|
|
|
|
args[1] = key
|
|
|
|
args = appendArgs(args, values)
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) RPushX(key string, values ...interface{}) *IntCmd {
|
|
|
|
args := make([]interface{}, 2, 2+len(values))
|
|
|
|
args[0] = "rpushx"
|
|
|
|
args[1] = key
|
|
|
|
args = appendArgs(args, values)
|
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SAdd(key string, members ...interface{}) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2, 2+len(members))
|
|
|
|
args[0] = "sadd"
|
|
|
|
args[1] = key
|
|
|
|
args = appendArgs(args, members)
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SCard(key string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("scard", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SDiff(keys ...string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
|
|
|
args[0] = "sdiff"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SDiffStore(destination string, keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
|
|
|
args[0] = "sdiffstore"
|
|
|
|
args[1] = destination
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SInter(keys ...string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
|
|
|
args[0] = "sinter"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SInterStore(destination string, keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
|
|
|
args[0] = "sinterstore"
|
|
|
|
args[1] = destination
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SIsMember(key string, member interface{}) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("sismember", key, member)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `SMEMBERS key` command output as a slice
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SMembers(key string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringSliceCmd("smembers", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `SMEMBERS key` command output as a map
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SMembersMap(key string) *StringStructMapCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringStructMapCmd("smembers", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SMove(source, destination string, member interface{}) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("smove", source, destination, member)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `SPOP key` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SPop(key string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("spop", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `SPOP key count` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SPopN(key string, count int64) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringSliceCmd("spop", key, count)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `SRANDMEMBER key` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SRandMember(key string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("srandmember", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `SRANDMEMBER key count` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SRandMemberN(key string, count int64) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringSliceCmd("srandmember", key, count)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SRem(key string, members ...interface{}) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2, 2+len(members))
|
|
|
|
args[0] = "srem"
|
|
|
|
args[1] = key
|
|
|
|
args = appendArgs(args, members)
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SUnion(keys ...string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
|
|
|
args[0] = "sunion"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SUnionStore(destination string, keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
|
|
|
args[0] = "sunionstore"
|
|
|
|
args[1] = destination
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type XAddArgs struct {
|
|
|
|
Stream string
|
|
|
|
MaxLen int64 // MAXLEN N
|
|
|
|
MaxLenApprox int64 // MAXLEN ~ N
|
|
|
|
ID string
|
|
|
|
Values map[string]interface{}
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XAdd(a *XAddArgs) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 0, 6+len(a.Values)*2)
|
|
|
|
args = append(args, "xadd")
|
|
|
|
args = append(args, a.Stream)
|
|
|
|
if a.MaxLen > 0 {
|
|
|
|
args = append(args, "maxlen", a.MaxLen)
|
|
|
|
} else if a.MaxLenApprox > 0 {
|
|
|
|
args = append(args, "maxlen", "~", a.MaxLenApprox)
|
|
|
|
}
|
|
|
|
if a.ID != "" {
|
|
|
|
args = append(args, a.ID)
|
|
|
|
} else {
|
|
|
|
args = append(args, "*")
|
|
|
|
}
|
|
|
|
for k, v := range a.Values {
|
|
|
|
args = append(args, k)
|
|
|
|
args = append(args, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := NewStringCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XDel(stream string, ids ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"xdel", stream}
|
|
|
|
for _, id := range ids {
|
|
|
|
args = append(args, id)
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XLen(stream string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("xlen", stream)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XRange(stream, start, stop string) *XMessageSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewXMessageSliceCmd("xrange", stream, start, stop)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XRangeN(stream, start, stop string, count int64) *XMessageSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewXMessageSliceCmd("xrange", stream, start, stop, "count", count)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XRevRange(stream, start, stop string) *XMessageSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewXMessageSliceCmd("xrevrange", stream, start, stop)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XRevRangeN(stream, start, stop string, count int64) *XMessageSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewXMessageSliceCmd("xrevrange", stream, start, stop, "count", count)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type XReadArgs struct {
|
2020-09-28 05:09:46 +08:00
|
|
|
Streams []string // list of streams and ids, e.g. stream1 stream2 id1 id2
|
2019-04-08 17:05:15 +08:00
|
|
|
Count int64
|
|
|
|
Block time.Duration
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XRead(a *XReadArgs) *XStreamSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 0, 5+len(a.Streams))
|
|
|
|
args = append(args, "xread")
|
|
|
|
if a.Count > 0 {
|
|
|
|
args = append(args, "count")
|
|
|
|
args = append(args, a.Count)
|
|
|
|
}
|
|
|
|
if a.Block >= 0 {
|
|
|
|
args = append(args, "block")
|
|
|
|
args = append(args, int64(a.Block/time.Millisecond))
|
|
|
|
}
|
2020-09-28 05:09:46 +08:00
|
|
|
|
2019-04-08 17:05:15 +08:00
|
|
|
args = append(args, "streams")
|
|
|
|
for _, s := range a.Streams {
|
|
|
|
args = append(args, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := NewXStreamSliceCmd(args...)
|
|
|
|
if a.Block >= 0 {
|
|
|
|
cmd.setReadTimeout(a.Block)
|
|
|
|
}
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XReadStreams(streams ...string) *XStreamSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.XRead(&XReadArgs{
|
|
|
|
Streams: streams,
|
|
|
|
Block: -1,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XGroupCreate(stream, group, start string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("xgroup", "create", stream, group, start)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XGroupCreateMkStream(stream, group, start string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("xgroup", "create", stream, group, start, "mkstream")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XGroupSetID(stream, group, start string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("xgroup", "setid", stream, group, start)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XGroupDestroy(stream, group string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("xgroup", "destroy", stream, group)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XGroupDelConsumer(stream, group, consumer string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("xgroup", "delconsumer", stream, group, consumer)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type XReadGroupArgs struct {
|
|
|
|
Group string
|
|
|
|
Consumer string
|
2020-09-28 05:09:46 +08:00
|
|
|
Streams []string // list of streams and ids, e.g. stream1 stream2 id1 id2
|
|
|
|
Count int64
|
|
|
|
Block time.Duration
|
|
|
|
NoAck bool
|
2019-04-08 17:05:15 +08:00
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XReadGroup(a *XReadGroupArgs) *XStreamSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 0, 8+len(a.Streams))
|
|
|
|
args = append(args, "xreadgroup", "group", a.Group, a.Consumer)
|
|
|
|
if a.Count > 0 {
|
|
|
|
args = append(args, "count", a.Count)
|
|
|
|
}
|
|
|
|
if a.Block >= 0 {
|
|
|
|
args = append(args, "block", int64(a.Block/time.Millisecond))
|
|
|
|
}
|
|
|
|
if a.NoAck {
|
|
|
|
args = append(args, "noack")
|
|
|
|
}
|
|
|
|
args = append(args, "streams")
|
|
|
|
for _, s := range a.Streams {
|
|
|
|
args = append(args, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := NewXStreamSliceCmd(args...)
|
|
|
|
if a.Block >= 0 {
|
|
|
|
cmd.setReadTimeout(a.Block)
|
|
|
|
}
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XAck(stream, group string, ids ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"xack", stream, group}
|
|
|
|
for _, id := range ids {
|
|
|
|
args = append(args, id)
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XPending(stream, group string) *XPendingCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewXPendingCmd("xpending", stream, group)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type XPendingExtArgs struct {
|
|
|
|
Stream string
|
|
|
|
Group string
|
|
|
|
Start string
|
|
|
|
End string
|
|
|
|
Count int64
|
|
|
|
Consumer string
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XPendingExt(a *XPendingExtArgs) *XPendingExtCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 0, 7)
|
|
|
|
args = append(args, "xpending", a.Stream, a.Group, a.Start, a.End, a.Count)
|
|
|
|
if a.Consumer != "" {
|
|
|
|
args = append(args, a.Consumer)
|
|
|
|
}
|
|
|
|
cmd := NewXPendingExtCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type XClaimArgs struct {
|
|
|
|
Stream string
|
|
|
|
Group string
|
|
|
|
Consumer string
|
|
|
|
MinIdle time.Duration
|
|
|
|
Messages []string
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XClaim(a *XClaimArgs) *XMessageSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := xClaimArgs(a)
|
|
|
|
cmd := NewXMessageSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XClaimJustID(a *XClaimArgs) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := xClaimArgs(a)
|
|
|
|
args = append(args, "justid")
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func xClaimArgs(a *XClaimArgs) []interface{} {
|
|
|
|
args := make([]interface{}, 0, 4+len(a.Messages))
|
|
|
|
args = append(args,
|
|
|
|
"xclaim",
|
|
|
|
a.Stream,
|
|
|
|
a.Group, a.Consumer,
|
|
|
|
int64(a.MinIdle/time.Millisecond))
|
|
|
|
for _, id := range a.Messages {
|
|
|
|
args = append(args, id)
|
|
|
|
}
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XTrim(key string, maxLen int64) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("xtrim", key, "maxlen", maxLen)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) XTrimApprox(key string, maxLen int64) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("xtrim", key, "maxlen", "~", maxLen)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c cmdable) XInfoGroups(key string) *XInfoGroupsCmd {
|
|
|
|
cmd := NewXInfoGroupsCmd(key)
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Z represents sorted set member.
|
|
|
|
type Z struct {
|
|
|
|
Score float64
|
|
|
|
Member interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ZWithKey represents sorted set member including the name of the key where it was popped.
|
|
|
|
type ZWithKey struct {
|
|
|
|
Z
|
|
|
|
Key string
|
|
|
|
}
|
|
|
|
|
|
|
|
// ZStore is used as an arg to ZInterStore and ZUnionStore.
|
|
|
|
type ZStore struct {
|
2020-09-28 05:09:46 +08:00
|
|
|
Keys []string
|
2019-04-08 17:05:15 +08:00
|
|
|
Weights []float64
|
|
|
|
// Can be SUM, MIN or MAX.
|
|
|
|
Aggregate string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `BZPOPMAX key [key ...] timeout` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BZPopMax(timeout time.Duration, keys ...string) *ZWithKeyCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys)+1)
|
|
|
|
args[0] = "bzpopmax"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
args[len(args)-1] = formatSec(timeout)
|
|
|
|
cmd := NewZWithKeyCmd(args...)
|
|
|
|
cmd.setReadTimeout(timeout)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `BZPOPMIN key [key ...] timeout` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BZPopMin(timeout time.Duration, keys ...string) *ZWithKeyCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys)+1)
|
|
|
|
args[0] = "bzpopmin"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
args[len(args)-1] = formatSec(timeout)
|
|
|
|
cmd := NewZWithKeyCmd(args...)
|
|
|
|
cmd.setReadTimeout(timeout)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) zAdd(a []interface{}, n int, members ...*Z) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
for i, m := range members {
|
|
|
|
a[n+2*i] = m.Score
|
|
|
|
a[n+2*i+1] = m.Member
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(a...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key score member [score member ...]` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZAdd(key string, members ...*Z) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
const n = 2
|
|
|
|
a := make([]interface{}, n+2*len(members))
|
|
|
|
a[0], a[1] = "zadd", key
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key NX score member [score member ...]` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZAddNX(key string, members ...*Z) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
const n = 3
|
|
|
|
a := make([]interface{}, n+2*len(members))
|
|
|
|
a[0], a[1], a[2] = "zadd", key, "nx"
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key XX score member [score member ...]` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZAddXX(key string, members ...*Z) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
const n = 3
|
|
|
|
a := make([]interface{}, n+2*len(members))
|
|
|
|
a[0], a[1], a[2] = "zadd", key, "xx"
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key CH score member [score member ...]` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZAddCh(key string, members ...*Z) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
const n = 3
|
|
|
|
a := make([]interface{}, n+2*len(members))
|
|
|
|
a[0], a[1], a[2] = "zadd", key, "ch"
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key NX CH score member [score member ...]` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZAddNXCh(key string, members ...*Z) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
const n = 4
|
|
|
|
a := make([]interface{}, n+2*len(members))
|
|
|
|
a[0], a[1], a[2], a[3] = "zadd", key, "nx", "ch"
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key XX CH score member [score member ...]` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZAddXXCh(key string, members ...*Z) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
const n = 4
|
|
|
|
a := make([]interface{}, n+2*len(members))
|
|
|
|
a[0], a[1], a[2], a[3] = "zadd", key, "xx", "ch"
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) zIncr(a []interface{}, n int, members ...*Z) *FloatCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
for i, m := range members {
|
|
|
|
a[n+2*i] = m.Score
|
|
|
|
a[n+2*i+1] = m.Member
|
|
|
|
}
|
|
|
|
cmd := NewFloatCmd(a...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key INCR score member` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZIncr(key string, member *Z) *FloatCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
const n = 3
|
|
|
|
a := make([]interface{}, n+2)
|
|
|
|
a[0], a[1], a[2] = "zadd", key, "incr"
|
|
|
|
return c.zIncr(a, n, member)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key NX INCR score member` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZIncrNX(key string, member *Z) *FloatCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
const n = 4
|
|
|
|
a := make([]interface{}, n+2)
|
|
|
|
a[0], a[1], a[2], a[3] = "zadd", key, "incr", "nx"
|
|
|
|
return c.zIncr(a, n, member)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key XX INCR score member` command.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZIncrXX(key string, member *Z) *FloatCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
const n = 4
|
|
|
|
a := make([]interface{}, n+2)
|
|
|
|
a[0], a[1], a[2], a[3] = "zadd", key, "incr", "xx"
|
|
|
|
return c.zIncr(a, n, member)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZCard(key string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("zcard", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZCount(key, min, max string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("zcount", key, min, max)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZLexCount(key, min, max string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("zlexcount", key, min, max)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZIncrBy(key string, increment float64, member string) *FloatCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewFloatCmd("zincrby", key, increment, member)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZInterStore(destination string, store *ZStore) *IntCmd {
|
|
|
|
args := make([]interface{}, 3+len(store.Keys))
|
2019-04-08 17:05:15 +08:00
|
|
|
args[0] = "zinterstore"
|
|
|
|
args[1] = destination
|
2020-09-28 05:09:46 +08:00
|
|
|
args[2] = len(store.Keys)
|
|
|
|
for i, key := range store.Keys {
|
2019-04-08 17:05:15 +08:00
|
|
|
args[3+i] = key
|
|
|
|
}
|
|
|
|
if len(store.Weights) > 0 {
|
|
|
|
args = append(args, "weights")
|
|
|
|
for _, weight := range store.Weights {
|
|
|
|
args = append(args, weight)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if store.Aggregate != "" {
|
|
|
|
args = append(args, "aggregate", store.Aggregate)
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZPopMax(key string, count ...int64) *ZSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{
|
|
|
|
"zpopmax",
|
|
|
|
key,
|
|
|
|
}
|
|
|
|
|
|
|
|
switch len(count) {
|
|
|
|
case 0:
|
|
|
|
break
|
|
|
|
case 1:
|
|
|
|
args = append(args, count[0])
|
|
|
|
default:
|
|
|
|
panic("too many arguments")
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := NewZSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZPopMin(key string, count ...int64) *ZSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{
|
|
|
|
"zpopmin",
|
|
|
|
key,
|
|
|
|
}
|
|
|
|
|
|
|
|
switch len(count) {
|
|
|
|
case 0:
|
|
|
|
break
|
|
|
|
case 1:
|
|
|
|
args = append(args, count[0])
|
|
|
|
default:
|
|
|
|
panic("too many arguments")
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := NewZSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) zRange(key string, start, stop int64, withScores bool) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{
|
|
|
|
"zrange",
|
|
|
|
key,
|
|
|
|
start,
|
|
|
|
stop,
|
|
|
|
}
|
|
|
|
if withScores {
|
|
|
|
args = append(args, "withscores")
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRange(key string, start, stop int64) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.zRange(key, start, stop, false)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewZSliceCmd("zrange", key, start, stop, "withscores")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type ZRangeBy struct {
|
|
|
|
Min, Max string
|
|
|
|
Offset, Count int64
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) zRangeBy(zcmd, key string, opt *ZRangeBy, withScores bool) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{zcmd, key, opt.Min, opt.Max}
|
|
|
|
if withScores {
|
|
|
|
args = append(args, "withscores")
|
|
|
|
}
|
|
|
|
if opt.Offset != 0 || opt.Count != 0 {
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
"limit",
|
|
|
|
opt.Offset,
|
|
|
|
opt.Count,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRangeByScore(key string, opt *ZRangeBy) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.zRangeBy("zrangebyscore", key, opt, false)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRangeByLex(key string, opt *ZRangeBy) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.zRangeBy("zrangebylex", key, opt, false)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRangeByScoreWithScores(key string, opt *ZRangeBy) *ZSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"zrangebyscore", key, opt.Min, opt.Max, "withscores"}
|
|
|
|
if opt.Offset != 0 || opt.Count != 0 {
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
"limit",
|
|
|
|
opt.Offset,
|
|
|
|
opt.Count,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
cmd := NewZSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRank(key, member string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("zrank", key, member)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRem(key string, members ...interface{}) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2, 2+len(members))
|
|
|
|
args[0] = "zrem"
|
|
|
|
args[1] = key
|
|
|
|
args = appendArgs(args, members)
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRemRangeByRank(key string, start, stop int64) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd(
|
|
|
|
"zremrangebyrank",
|
|
|
|
key,
|
|
|
|
start,
|
|
|
|
stop,
|
|
|
|
)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRemRangeByScore(key, min, max string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("zremrangebyscore", key, min, max)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRemRangeByLex(key, min, max string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("zremrangebylex", key, min, max)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRevRange(key string, start, stop int64) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringSliceCmd("zrevrange", key, start, stop)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewZSliceCmd("zrevrange", key, start, stop, "withscores")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) zRevRangeBy(zcmd, key string, opt *ZRangeBy) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{zcmd, key, opt.Max, opt.Min}
|
|
|
|
if opt.Offset != 0 || opt.Count != 0 {
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
"limit",
|
|
|
|
opt.Offset,
|
|
|
|
opt.Count,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRevRangeByScore(key string, opt *ZRangeBy) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.zRevRangeBy("zrevrangebyscore", key, opt)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRevRangeByLex(key string, opt *ZRangeBy) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.zRevRangeBy("zrevrangebylex", key, opt)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRevRangeByScoreWithScores(key string, opt *ZRangeBy) *ZSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"zrevrangebyscore", key, opt.Max, opt.Min, "withscores"}
|
|
|
|
if opt.Offset != 0 || opt.Count != 0 {
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
"limit",
|
|
|
|
opt.Offset,
|
|
|
|
opt.Count,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
cmd := NewZSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZRevRank(key, member string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("zrevrank", key, member)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZScore(key, member string) *FloatCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewFloatCmd("zscore", key, member)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ZUnionStore(dest string, store *ZStore) *IntCmd {
|
|
|
|
args := make([]interface{}, 3+len(store.Keys))
|
2019-04-08 17:05:15 +08:00
|
|
|
args[0] = "zunionstore"
|
|
|
|
args[1] = dest
|
2020-09-28 05:09:46 +08:00
|
|
|
args[2] = len(store.Keys)
|
|
|
|
for i, key := range store.Keys {
|
2019-04-08 17:05:15 +08:00
|
|
|
args[3+i] = key
|
|
|
|
}
|
|
|
|
if len(store.Weights) > 0 {
|
|
|
|
args = append(args, "weights")
|
|
|
|
for _, weight := range store.Weights {
|
|
|
|
args = append(args, weight)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if store.Aggregate != "" {
|
|
|
|
args = append(args, "aggregate", store.Aggregate)
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) PFAdd(key string, els ...interface{}) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2, 2+len(els))
|
|
|
|
args[0] = "pfadd"
|
|
|
|
args[1] = key
|
|
|
|
args = appendArgs(args, els)
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) PFCount(keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
|
|
|
args[0] = "pfcount"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) PFMerge(dest string, keys ...string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
|
|
|
args[0] = "pfmerge"
|
|
|
|
args[1] = dest
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewStatusCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BgRewriteAOF() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("bgrewriteaof")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) BgSave() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("bgsave")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClientKill(ipPort string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("client", "kill", ipPort)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClientKillByFilter is new style synx, while the ClientKill is old
|
|
|
|
// CLIENT KILL <option> [value] ... <option> [value]
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClientKillByFilter(keys ...string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
|
|
|
args[0] = "client"
|
|
|
|
args[1] = "kill"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClientList() *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("client", "list")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClientPause(dur time.Duration) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("client", "pause", formatMs(dur))
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClientID() *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("client", "id")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClientUnblock(id int64) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("client", "unblock", id)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClientUnblockWithError(id int64) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("client", "unblock", id, "error")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClientSetName assigns a name to the connection.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c statefulCmdable) ClientSetName(name string) *BoolCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewBoolCmd("client", "setname", name)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClientGetName returns the name of the connection.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClientGetName() *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("client", "getname")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ConfigGet(parameter string) *SliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewSliceCmd("config", "get", parameter)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ConfigResetStat() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("config", "resetstat")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ConfigSet(parameter, value string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("config", "set", parameter, value)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ConfigRewrite() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("config", "rewrite")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deperecated. Use DBSize instead.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) DbSize() *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.DBSize()
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) DBSize() *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("dbsize")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) FlushAll() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("flushall")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) FlushAllAsync() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("flushall", "async")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) FlushDB() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("flushdb")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) FlushDBAsync() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("flushdb", "async")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Info(section ...string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"info"}
|
|
|
|
if len(section) > 0 {
|
|
|
|
args = append(args, section[0])
|
|
|
|
}
|
|
|
|
cmd := NewStringCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) LastSave() *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("lastsave")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Save() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("save")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) shutdown(modifier string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
var args []interface{}
|
|
|
|
if modifier == "" {
|
|
|
|
args = []interface{}{"shutdown"}
|
|
|
|
} else {
|
|
|
|
args = []interface{}{"shutdown", modifier}
|
|
|
|
}
|
|
|
|
cmd := NewStatusCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
if err := cmd.Err(); err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
// Server quit as expected.
|
|
|
|
cmd.err = nil
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Server did not quit. String reply contains the reason.
|
|
|
|
cmd.err = errors.New(cmd.val)
|
|
|
|
cmd.val = ""
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Shutdown() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.shutdown("")
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ShutdownSave() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.shutdown("save")
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ShutdownNoSave() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
return c.shutdown("nosave")
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SlaveOf(host, port string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("slaveof", host, port)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) SlowLog() {
|
2019-04-08 17:05:15 +08:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Sync() {
|
2019-04-08 17:05:15 +08:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Time() *TimeCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewTimeCmd("time")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Eval(script string, keys []string, args ...interface{}) *Cmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmdArgs := make([]interface{}, 3+len(keys), 3+len(keys)+len(args))
|
|
|
|
cmdArgs[0] = "eval"
|
|
|
|
cmdArgs[1] = script
|
|
|
|
cmdArgs[2] = len(keys)
|
|
|
|
for i, key := range keys {
|
|
|
|
cmdArgs[3+i] = key
|
|
|
|
}
|
|
|
|
cmdArgs = appendArgs(cmdArgs, args)
|
|
|
|
cmd := NewCmd(cmdArgs...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmdArgs := make([]interface{}, 3+len(keys), 3+len(keys)+len(args))
|
|
|
|
cmdArgs[0] = "evalsha"
|
|
|
|
cmdArgs[1] = sha1
|
|
|
|
cmdArgs[2] = len(keys)
|
|
|
|
for i, key := range keys {
|
|
|
|
cmdArgs[3+i] = key
|
|
|
|
}
|
|
|
|
cmdArgs = appendArgs(cmdArgs, args)
|
|
|
|
cmd := NewCmd(cmdArgs...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ScriptExists(hashes ...string) *BoolSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(hashes))
|
|
|
|
args[0] = "script"
|
|
|
|
args[1] = "exists"
|
|
|
|
for i, hash := range hashes {
|
|
|
|
args[2+i] = hash
|
|
|
|
}
|
|
|
|
cmd := NewBoolSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ScriptFlush() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("script", "flush")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ScriptKill() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("script", "kill")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ScriptLoad(script string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("script", "load", script)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) DebugObject(key string) *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("debug", "object", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Publish posts the message to the channel.
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) Publish(channel string, message interface{}) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("publish", channel, message)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) PubSubChannels(pattern string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"pubsub", "channels"}
|
|
|
|
if pattern != "*" {
|
|
|
|
args = append(args, pattern)
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) PubSubNumSub(channels ...string) *StringIntMapCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(channels))
|
|
|
|
args[0] = "pubsub"
|
|
|
|
args[1] = "numsub"
|
|
|
|
for i, channel := range channels {
|
|
|
|
args[2+i] = channel
|
|
|
|
}
|
|
|
|
cmd := NewStringIntMapCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) PubSubNumPat() *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("pubsub", "numpat")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterSlots() *ClusterSlotsCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewClusterSlotsCmd("cluster", "slots")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterNodes() *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("cluster", "nodes")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterMeet(host, port string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("cluster", "meet", host, port)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterForget(nodeID string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("cluster", "forget", nodeID)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterReplicate(nodeID string) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("cluster", "replicate", nodeID)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterResetSoft() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("cluster", "reset", "soft")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterResetHard() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("cluster", "reset", "hard")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterInfo() *StringCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringCmd("cluster", "info")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterKeySlot(key string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("cluster", "keyslot", key)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterGetKeysInSlot(slot int, count int) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringSliceCmd("cluster", "getkeysinslot", slot, count)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterCountFailureReports(nodeID string) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("cluster", "count-failure-reports", nodeID)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterCountKeysInSlot(slot int) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewIntCmd("cluster", "countkeysinslot", slot)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterDelSlots(slots ...int) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(slots))
|
|
|
|
args[0] = "cluster"
|
|
|
|
args[1] = "delslots"
|
|
|
|
for i, slot := range slots {
|
|
|
|
args[2+i] = slot
|
|
|
|
}
|
|
|
|
cmd := NewStatusCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterDelSlotsRange(min, max int) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
size := max - min + 1
|
|
|
|
slots := make([]int, size)
|
|
|
|
for i := 0; i < size; i++ {
|
|
|
|
slots[i] = min + i
|
|
|
|
}
|
|
|
|
return c.ClusterDelSlots(slots...)
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterSaveConfig() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("cluster", "saveconfig")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterSlaves(nodeID string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStringSliceCmd("cluster", "slaves", nodeID)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ReadOnly() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("readonly")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ReadWrite() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("readwrite")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterFailover() *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
cmd := NewStatusCmd("cluster", "failover")
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterAddSlots(slots ...int) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(slots))
|
|
|
|
args[0] = "cluster"
|
|
|
|
args[1] = "addslots"
|
|
|
|
for i, num := range slots {
|
|
|
|
args[2+i] = num
|
|
|
|
}
|
|
|
|
cmd := NewStatusCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) ClusterAddSlotsRange(min, max int) *StatusCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
size := max - min + 1
|
|
|
|
slots := make([]int, size)
|
|
|
|
for i := 0; i < size; i++ {
|
|
|
|
slots[i] = min + i
|
|
|
|
}
|
|
|
|
return c.ClusterAddSlots(slots...)
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+3*len(geoLocation))
|
|
|
|
args[0] = "geoadd"
|
|
|
|
args[1] = key
|
|
|
|
for i, eachLoc := range geoLocation {
|
|
|
|
args[2+3*i] = eachLoc.Longitude
|
|
|
|
args[2+3*i+1] = eachLoc.Latitude
|
|
|
|
args[2+3*i+2] = eachLoc.Name
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
// GeoRadius is a read-only GEORADIUS_RO command.
|
|
|
|
func (c cmdable) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd {
|
|
|
|
cmd := NewGeoLocationCmd(query, "georadius_ro", key, longitude, latitude)
|
|
|
|
if query.Store != "" || query.StoreDist != "" {
|
|
|
|
cmd.SetErr(errors.New("GeoRadius does not support Store or StoreDist"))
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
// GeoRadiusStore is a writing GEORADIUS command.
|
|
|
|
func (c cmdable) GeoRadiusStore(key string, longitude, latitude float64, query *GeoRadiusQuery) *IntCmd {
|
|
|
|
args := geoLocationArgs(query, "georadius", key, longitude, latitude)
|
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
if query.Store == "" && query.StoreDist == "" {
|
|
|
|
cmd.SetErr(errors.New("GeoRadiusStore requires Store or StoreDist"))
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
// GeoRadius is a read-only GEORADIUSBYMEMBER_RO command.
|
|
|
|
func (c cmdable) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd {
|
|
|
|
cmd := NewGeoLocationCmd(query, "georadiusbymember_ro", key, member)
|
|
|
|
if query.Store != "" || query.StoreDist != "" {
|
|
|
|
cmd.SetErr(errors.New("GeoRadiusByMember does not support Store or StoreDist"))
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
// GeoRadiusByMemberStore is a writing GEORADIUSBYMEMBER command.
|
|
|
|
func (c cmdable) GeoRadiusByMemberStore(key, member string, query *GeoRadiusQuery) *IntCmd {
|
|
|
|
args := geoLocationArgs(query, "georadiusbymember", key, member)
|
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
if query.Store == "" && query.StoreDist == "" {
|
|
|
|
cmd.SetErr(errors.New("GeoRadiusByMemberStore requires Store or StoreDist"))
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) GeoDist(key string, member1, member2, unit string) *FloatCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
if unit == "" {
|
|
|
|
unit = "km"
|
|
|
|
}
|
|
|
|
cmd := NewFloatCmd("geodist", key, member1, member2, unit)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) GeoHash(key string, members ...string) *StringSliceCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(members))
|
|
|
|
args[0] = "geohash"
|
|
|
|
args[1] = key
|
|
|
|
for i, member := range members {
|
|
|
|
args[2+i] = member
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) GeoPos(key string, members ...string) *GeoPosCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := make([]interface{}, 2+len(members))
|
|
|
|
args[0] = "geopos"
|
|
|
|
args[1] = key
|
|
|
|
for i, member := range members {
|
|
|
|
args[2+i] = member
|
|
|
|
}
|
|
|
|
cmd := NewGeoPosCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2020-09-28 05:09:46 +08:00
|
|
|
func (c cmdable) MemoryUsage(key string, samples ...int) *IntCmd {
|
2019-04-08 17:05:15 +08:00
|
|
|
args := []interface{}{"memory", "usage", key}
|
|
|
|
if len(samples) > 0 {
|
|
|
|
if len(samples) != 1 {
|
|
|
|
panic("MemoryUsage expects single sample count")
|
|
|
|
}
|
|
|
|
args = append(args, "SAMPLES", samples[0])
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2020-09-28 05:09:46 +08:00
|
|
|
_ = c(cmd)
|
2019-04-08 17:05:15 +08:00
|
|
|
return cmd
|
|
|
|
}
|