redis/commands.go

2557 lines
62 KiB
Go
Raw Normal View History

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