2012-07-25 17:00:50 +04:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
2014-11-13 15:26:14 +03:00
|
|
|
"io"
|
2012-07-25 17:00:50 +04:00
|
|
|
"strconv"
|
2014-05-11 11:42:40 +04:00
|
|
|
"time"
|
2016-04-09 14:52:01 +03:00
|
|
|
|
|
|
|
"gopkg.in/redis.v4/internal"
|
2016-07-02 15:52:10 +03:00
|
|
|
"gopkg.in/redis.v4/internal/errors"
|
2012-07-25 17:00:50 +04:00
|
|
|
)
|
|
|
|
|
2015-04-07 12:42:16 +03:00
|
|
|
func readTimeout(timeout time.Duration) time.Duration {
|
|
|
|
if timeout == 0 {
|
2014-05-11 11:42:40 +04:00
|
|
|
return 0
|
|
|
|
}
|
2015-04-07 12:42:16 +03:00
|
|
|
return timeout + time.Second
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
func usePrecise(dur time.Duration) bool {
|
|
|
|
return dur < time.Second || dur%time.Second != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func formatMs(dur time.Duration) string {
|
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,
|
|
|
|
)
|
|
|
|
}
|
2016-07-02 15:52:10 +03:00
|
|
|
return strconv.FormatInt(int64(dur/time.Millisecond), 10)
|
2015-01-31 12:08:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func formatSec(dur time.Duration) string {
|
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,
|
|
|
|
)
|
|
|
|
}
|
2016-07-02 15:52:10 +03:00
|
|
|
return strconv.FormatInt(int64(dur/time.Second), 10)
|
2015-05-28 15:51:19 +03:00
|
|
|
}
|
|
|
|
|
2016-06-05 12:45:39 +03:00
|
|
|
type cmdable struct {
|
2016-06-17 15:09:38 +03:00
|
|
|
process func(cmd Cmder) error
|
2015-05-28 15:51:19 +03:00
|
|
|
}
|
|
|
|
|
2016-06-05 12:45:39 +03:00
|
|
|
type statefulCmdable struct {
|
2016-06-17 15:09:38 +03:00
|
|
|
process func(cmd Cmder) error
|
2015-01-31 12:08:56 +03:00
|
|
|
}
|
|
|
|
|
2012-07-27 18:21:50 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *statefulCmdable) Auth(password string) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("auth", password)
|
2016-06-05 12:45:39 +03:00
|
|
|
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 {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("echo", message)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-06-05 12:45:39 +03:00
|
|
|
func (c *cmdable) Ping() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("ping")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Quit() *StatusCmd {
|
2012-08-25 16:40:49 +04:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *statefulCmdable) Select(index int) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("select", index)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Del(keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
2016-07-08 12:24:02 +03:00
|
|
|
args[0] = "del"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Dump(key string) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("dump", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Exists(key string) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("exists", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Expire(key string, expiration time.Duration) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("expire", key, formatSec(expiration))
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ExpireAt(key string, tm time.Time) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("expireat", key, tm.Unix())
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Keys(pattern string) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringSliceCmd("keys", pattern)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03: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(
|
2016-05-06 21:12:31 +03:00
|
|
|
"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
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd.setReadTimeout(readTimeout(timeout))
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Move(key string, db int64) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("move", key, db)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ObjectRefCount(keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "object"
|
|
|
|
args[1] = "refcount"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ObjectEncoding(keys ...string) *StringCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "object"
|
|
|
|
args[1] = "encoding"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ObjectIdleTime(keys ...string) *DurationCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "object"
|
|
|
|
args[1] = "idletime"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewDurationCmd(time.Second, args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Persist(key string) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("persist", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) PExpire(key string, expiration time.Duration) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("pexpire", key, formatMs(expiration))
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) PExpireAt(key string, tm time.Time) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd(
|
2016-05-06 21:12:31 +03:00
|
|
|
"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
|
|
|
)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) PTTL(key string) *DurationCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewDurationCmd(time.Millisecond, "pttl", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) RandomKey() *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("randomkey")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Rename(key, newkey string) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("rename", key, newkey)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) RenameNX(key, newkey string) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("renamenx", key, newkey)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Restore(key string, ttl time.Duration, value string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(
|
2016-05-06 21:12:31 +03:00
|
|
|
"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,
|
|
|
|
)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd {
|
2015-07-11 12:23:04 +03:00
|
|
|
cmd := NewStatusCmd(
|
2016-05-06 21:12:31 +03:00
|
|
|
"restore",
|
2015-07-11 12:23:04 +03:00
|
|
|
key,
|
|
|
|
formatMs(ttl),
|
|
|
|
value,
|
2016-05-06 21:12:31 +03:00
|
|
|
"replace",
|
2015-07-11 12:23:04 +03:00
|
|
|
)
|
2016-06-05 12:45:39 +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
|
|
|
|
Offset, Count float64
|
|
|
|
Get []string
|
|
|
|
Order string
|
|
|
|
IsAlpha bool
|
|
|
|
Store string
|
|
|
|
}
|
|
|
|
|
2016-01-22 13:29:23 +03:00
|
|
|
func (sort *Sort) args(key string) []interface{} {
|
2016-05-06 21:12:31 +03:00
|
|
|
args := []interface{}{"sort", key}
|
2012-08-17 22:36:48 +04:00
|
|
|
if sort.By != "" {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "by", sort.By)
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
|
|
|
if sort.Offset != 0 || sort.Count != 0 {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "limit", sort.Offset, sort.Count)
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
|
|
|
for _, get := range sort.Get {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "get", get)
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
|
|
|
if sort.Order != "" {
|
|
|
|
args = append(args, sort.Order)
|
|
|
|
}
|
|
|
|
if sort.IsAlpha {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "alpha")
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
|
|
|
if sort.Store != "" {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "store", sort.Store)
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
2016-01-22 13:29:23 +03:00
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Sort(key string, sort Sort) *StringSliceCmd {
|
2016-01-22 13:29:23 +03:00
|
|
|
cmd := NewStringSliceCmd(sort.args(key)...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2016-01-22 13:29:23 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SortInterfaces(key string, sort Sort) *SliceCmd {
|
2016-01-22 13:29:23 +03:00
|
|
|
cmd := NewSliceCmd(sort.args(key)...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) TTL(key string) *DurationCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewDurationCmd(time.Second, "ttl", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Type(key string) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("type", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Scan(cursor uint64, match string, count int64) Scanner {
|
2016-05-06 21:12:31 +03:00
|
|
|
args := []interface{}{"scan", cursor}
|
2014-05-11 11:42:40 +04:00
|
|
|
if match != "" {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "match", match)
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
if count > 0 {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "count", count)
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewScanCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2016-04-13 11:52:47 +03:00
|
|
|
return Scanner{
|
|
|
|
client: c,
|
|
|
|
ScanCmd: cmd,
|
|
|
|
}
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SScan(key string, cursor uint64, match string, count int64) Scanner {
|
2016-05-06 21:12:31 +03:00
|
|
|
args := []interface{}{"sscan", key, cursor}
|
2014-05-11 11:42:40 +04:00
|
|
|
if match != "" {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "match", match)
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
if count > 0 {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "count", count)
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewScanCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2016-04-13 11:52:47 +03:00
|
|
|
return Scanner{
|
|
|
|
client: c,
|
|
|
|
ScanCmd: cmd,
|
|
|
|
}
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HScan(key string, cursor uint64, match string, count int64) Scanner {
|
2016-05-06 21:12:31 +03:00
|
|
|
args := []interface{}{"hscan", key, cursor}
|
2014-05-11 11:42:40 +04:00
|
|
|
if match != "" {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "match", match)
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
if count > 0 {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "count", count)
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewScanCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2016-04-13 11:52:47 +03:00
|
|
|
return Scanner{
|
|
|
|
client: c,
|
|
|
|
ScanCmd: cmd,
|
|
|
|
}
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZScan(key string, cursor uint64, match string, count int64) Scanner {
|
2016-05-06 21:12:31 +03:00
|
|
|
args := []interface{}{"zscan", key, cursor}
|
2014-05-11 11:42:40 +04:00
|
|
|
if match != "" {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "match", match)
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
if count > 0 {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "count", count)
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewScanCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2016-04-13 11:52:47 +03:00
|
|
|
return Scanner{
|
|
|
|
client: c,
|
|
|
|
ScanCmd: cmd,
|
|
|
|
}
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Append(key, value string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("append", key, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) BitCount(key string, bitCount *BitCount) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-19 16:57:58 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) bitOp(op, destKey string, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 3+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "bitop"
|
2015-05-28 15:51:19 +03:00
|
|
|
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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
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
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) BitOpAnd(destKey string, keys ...string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
return c.bitOp("and", destKey, keys...)
|
2012-08-19 16:57:58 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) BitOpOr(destKey string, keys ...string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
return c.bitOp("or", destKey, keys...)
|
2012-08-19 16:57:58 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) BitOpXor(destKey string, keys ...string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
return c.bitOp("xor", destKey, keys...)
|
2012-08-19 16:57:58 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) BitOpNot(destKey string, key string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
return c.bitOp("not", destKey, key)
|
2012-08-19 16:57:58 +04:00
|
|
|
}
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) BitPos(key string, bit int64, pos ...int64) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 3+len(pos))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "bitpos"
|
2015-05-28 15:51:19 +03:00
|
|
|
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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-10-07 14:54:43 +04:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Decr(key string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("decr", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) DecrBy(key string, decrement int64) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("decrby", key, decrement)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Get(key string) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("get", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) GetBit(key string, offset int64) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("getbit", key, offset)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) GetRange(key string, start, end int64) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("getrange", key, start, end)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) GetSet(key string, value interface{}) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("getset", key, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Incr(key string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("incr", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) IncrBy(key string, value int64) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("incrby", key, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) IncrByFloat(key string, value float64) *FloatCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewFloatCmd("incrbyfloat", key, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
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
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) MGet(keys ...string) *SliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "mget"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewSliceCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) MSet(pairs ...interface{}) *StatusCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 1+len(pairs))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "mset"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, pair := range pairs {
|
|
|
|
args[1+i] = pair
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) MSetNX(pairs ...interface{}) *BoolCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 1+len(pairs))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "msetnx"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, pair := range pairs {
|
|
|
|
args[1+i] = pair
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd(args...)
|
2016-06-05 12:45:39 +03: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]` command.
|
|
|
|
//
|
|
|
|
// Zero expiration means the key has no expiration time.
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
args := make([]interface{}, 3, 4)
|
|
|
|
args[0] = "set"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = key
|
|
|
|
args[2] = value
|
2015-01-31 12:08:56 +03:00
|
|
|
if expiration > 0 {
|
|
|
|
if usePrecise(expiration) {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "px", formatMs(expiration))
|
2015-01-31 12:08:56 +03:00
|
|
|
} else {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "ex", formatSec(expiration))
|
2015-01-31 12:08:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd := NewStatusCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SetBit(key string, offset int64, value int) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(
|
2012-07-26 19:16:17 +04:00
|
|
|
"SETBIT",
|
|
|
|
key,
|
2015-10-07 18:21:18 +03:00
|
|
|
offset,
|
|
|
|
value,
|
2012-07-26 19:16:17 +04:00
|
|
|
)
|
2016-06-05 12:45:39 +03: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.
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd {
|
2015-01-31 12:08:56 +03:00
|
|
|
var cmd *BoolCmd
|
|
|
|
if expiration == 0 {
|
|
|
|
// Use old `SETNX` to support old Redis versions.
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd = NewBoolCmd("setnx", key, value)
|
2015-01-31 12:08:56 +03:00
|
|
|
} else {
|
|
|
|
if usePrecise(expiration) {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd = NewBoolCmd("set", key, value, "px", formatMs(expiration), "nx")
|
2015-01-31 12:08:56 +03:00
|
|
|
} else {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd = NewBoolCmd("set", key, value, "ex", formatSec(expiration), "nx")
|
2015-01-31 12:08:56 +03:00
|
|
|
}
|
|
|
|
}
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-01-31 12:08:56 +03:00
|
|
|
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.
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd {
|
2015-01-31 12:08:56 +03:00
|
|
|
var cmd *BoolCmd
|
|
|
|
if usePrecise(expiration) {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd = NewBoolCmd("set", key, value, "px", formatMs(expiration), "xx")
|
2015-01-31 12:08:56 +03:00
|
|
|
} else {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd = NewBoolCmd("set", key, value, "ex", formatSec(expiration), "xx")
|
2015-01-31 12:08:56 +03:00
|
|
|
}
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SetRange(key string, offset int64, value string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("setrange", key, offset, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) StrLen(key string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("strlen", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HDel(key string, fields ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(fields))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "hdel"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = key
|
|
|
|
for i, field := range fields {
|
|
|
|
args[2+i] = field
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HExists(key, field string) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("hexists", key, field)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HGet(key, field string) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("hget", key, field)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HGetAll(key string) *StringStringMapCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringStringMapCmd("hgetall", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2013-02-02 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HIncrBy(key, field string, incr int64) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("hincrby", key, field, incr)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HIncrByFloat(key, field string, incr float64) *FloatCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewFloatCmd("hincrbyfloat", key, field, incr)
|
2016-06-05 12:45:39 +03:00
|
|
|
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
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HKeys(key string) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringSliceCmd("hkeys", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HLen(key string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("hlen", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HMGet(key string, fields ...string) *SliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(fields))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "hmget"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = key
|
|
|
|
for i, field := range fields {
|
|
|
|
args[2+i] = field
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewSliceCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
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
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HMSet(key string, fields map[string]string) *StatusCmd {
|
2016-05-02 14:50:59 +03:00
|
|
|
args := make([]interface{}, 2+len(fields)*2)
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "hmset"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = key
|
2016-05-02 14:50:59 +03:00
|
|
|
i := 2
|
|
|
|
for k, v := range fields {
|
|
|
|
args[i] = k
|
|
|
|
args[i+1] = v
|
|
|
|
i += 2
|
2015-05-28 15:51:19 +03:00
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HSet(key, field, value string) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("hset", key, field, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HSetNX(key, field, value string) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("hsetnx", key, field, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) HVals(key string) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringSliceCmd("hvals", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
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
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
args := make([]interface{}, 1+len(keys)+1)
|
|
|
|
args[0] = "blpop"
|
2015-05-28 15:51:19 +03:00
|
|
|
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(readTimeout(timeout))
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
args := make([]interface{}, 1+len(keys)+1)
|
|
|
|
args[0] = "brpop"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
2016-05-06 21:12:31 +03:00
|
|
|
args[len(keys)+1] = formatSec(timeout)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(args...)
|
|
|
|
cmd.setReadTimeout(readTimeout(timeout))
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) BRPopLPush(source, destination string, timeout time.Duration) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd(
|
2016-05-06 21:12:31 +03:00
|
|
|
"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
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd.setReadTimeout(readTimeout(timeout))
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) LIndex(key string, index int64) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("lindex", key, index)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) LInsert(key, op string, pivot, value interface{}) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("linsert", key, op, pivot, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03: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
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) LLen(key string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("llen", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) LPop(key string) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("lpop", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) LPush(key string, values ...interface{}) *IntCmd {
|
2015-12-12 18:41:49 +03:00
|
|
|
args := make([]interface{}, 2+len(values))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "lpush"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = key
|
2015-12-12 18:41:49 +03:00
|
|
|
for i, value := range values {
|
|
|
|
args[2+i] = value
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) LPushX(key string, value interface{}) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("lpushx", key, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) LRange(key string, start, stop int64) *StringSliceCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(
|
2016-05-06 21:12:31 +03:00
|
|
|
"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
|
|
|
)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) LRem(key string, count int64, value interface{}) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("lrem", key, count, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) LSet(key string, index int64, value interface{}) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("lset", key, index, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) LTrim(key string, start, stop int64) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(
|
2016-05-06 21:12:31 +03:00
|
|
|
"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
|
|
|
)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) RPop(key string) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("rpop", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) RPopLPush(source, destination string) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("rpoplpush", source, destination)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) RPush(key string, values ...interface{}) *IntCmd {
|
2015-12-12 18:41:49 +03:00
|
|
|
args := make([]interface{}, 2+len(values))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "rpush"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = key
|
2015-12-12 18:41:49 +03:00
|
|
|
for i, value := range values {
|
|
|
|
args[2+i] = value
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) RPushX(key string, value interface{}) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("rpushx", key, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SAdd(key string, members ...interface{}) *IntCmd {
|
2015-12-12 18:41:49 +03:00
|
|
|
args := make([]interface{}, 2+len(members))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "sadd"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = key
|
2015-12-12 18:41:49 +03:00
|
|
|
for i, member := range members {
|
|
|
|
args[2+i] = member
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
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
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SCard(key string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("scard", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SDiff(keys ...string) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "sdiff"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SDiffStore(destination string, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "sdiffstore"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = destination
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SInter(keys ...string) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "sinter"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SInterStore(destination string, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "sinterstore"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = destination
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SIsMember(key string, member interface{}) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("sismember", key, member)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SMembers(key string) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringSliceCmd("smembers", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SMove(source, destination string, member interface{}) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("smove", source, destination, member)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-06-09 18:39:51 +03:00
|
|
|
// Redis `SPOP key` command.
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SPop(key string) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("spop", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-06-09 18:39:51 +03:00
|
|
|
// Redis `SPOP key count` command.
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SPopN(key string, count int64) *StringSliceCmd {
|
2016-06-09 18:39:51 +03:00
|
|
|
cmd := NewStringSliceCmd("spop", key, count)
|
|
|
|
c.process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-08-25 14:02:16 +03:00
|
|
|
// Redis `SRANDMEMBER key` command.
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SRandMember(key string) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("srandmember", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
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.
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SRandMemberN(key string, count int64) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringSliceCmd("srandmember", key, count)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-08-25 14:02:16 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SRem(key string, members ...interface{}) *IntCmd {
|
2015-12-12 18:41:49 +03:00
|
|
|
args := make([]interface{}, 2+len(members))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "srem"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = key
|
2015-12-12 18:41:49 +03:00
|
|
|
for i, member := range members {
|
|
|
|
args[2+i] = member
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SUnion(keys ...string) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "sunion"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SUnionStore(destination string, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "sunionstore"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = destination
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-26 19:16:17 +04: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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-08-29 13:08:27 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key score member [score member ...]` command.
|
2016-07-01 15:25:28 +03:00
|
|
|
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))
|
2016-05-06 21:12:31 +03:00
|
|
|
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.
|
2016-07-01 15:25:28 +03:00
|
|
|
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))
|
2016-05-06 21:12:31 +03:00
|
|
|
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.
|
2016-07-01 15:25:28 +03:00
|
|
|
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))
|
2016-05-06 21:12:31 +03:00
|
|
|
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.
|
2016-07-01 15:25:28 +03:00
|
|
|
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))
|
2016-05-06 21:12:31 +03:00
|
|
|
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.
|
2016-07-01 15:25:28 +03:00
|
|
|
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))
|
2016-05-06 21:12:31 +03:00
|
|
|
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.
|
2016-07-01 15:25:28 +03:00
|
|
|
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))
|
2016-05-06 21:12:31 +03:00
|
|
|
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...)
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) zIncr(a []interface{}, n int, members ...Z) *FloatCmd {
|
2015-05-11 16:41:42 +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
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
2015-08-29 13:08:27 +03:00
|
|
|
cmd := NewFloatCmd(a...)
|
2016-06-05 12:45:39 +03:00
|
|
|
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.
|
2016-07-01 15:25:28 +03:00
|
|
|
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)
|
2016-05-06 21:12:31 +03:00
|
|
|
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.
|
2016-07-01 15:25:28 +03:00
|
|
|
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)
|
2016-05-06 21:12:31 +03:00
|
|
|
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.
|
2016-07-01 15:25:28 +03:00
|
|
|
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)
|
2016-05-06 21:12:31 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZCard(key string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("zcard", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZCount(key, min, max string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("zcount", key, min, max)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZIncrBy(key string, increment float64, member string) *FloatCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewFloatCmd("zincrby", key, increment, member)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZInterStore(destination string, store ZStore, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 3+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "zinterstore"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = destination
|
|
|
|
args[2] = strconv.Itoa(len(keys))
|
|
|
|
for i, key := range keys {
|
|
|
|
args[3+i] = key
|
|
|
|
}
|
2012-08-17 22:36:48 +04:00
|
|
|
if len(store.Weights) > 0 {
|
2016-05-06 21:12:31 +03:00
|
|
|
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 != "" {
|
2016-05-06 21:12:31 +03:00
|
|
|
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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) zRange(key string, start, stop int64, withScores bool) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := []interface{}{
|
2016-05-06 21:12:31 +03:00
|
|
|
"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 {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = append(args, "withscores")
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03: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)
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewZSliceCmd("zrange", key, start, stop, "withscores")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2013-02-02 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2016-04-09 13:15:33 +03:00
|
|
|
type ZRangeBy struct {
|
2015-03-30 16:14:21 +03:00
|
|
|
Min, Max string
|
2014-05-11 11:42:40 +04:00
|
|
|
Offset, Count int64
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) zRangeBy(zcmd, key string, opt ZRangeBy, withScores bool) *StringSliceCmd {
|
2015-08-25 22:15:01 +03:00
|
|
|
args := []interface{}{zcmd, key, opt.Min, opt.Max}
|
2012-07-27 18:21:50 +04:00
|
|
|
if withScores {
|
2016-05-06 21:12:31 +03:00
|
|
|
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,
|
2016-05-06 21:12:31 +03:00
|
|
|
"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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
return c.zRangeBy("zrangebyscore", key, opt, false)
|
2015-08-23 06:38:37 +03:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
return c.zRangeBy("zrangebylex", key, opt, false)
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
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,
|
2016-05-06 21:12:31 +03:00
|
|
|
"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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2013-02-02 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRank(key, member string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("zrank", key, member)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRem(key string, members ...interface{}) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(members))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "zrem"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = key
|
|
|
|
for i, member := range members {
|
|
|
|
args[2+i] = member
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRemRangeByRank(key string, start, stop int64) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(
|
2016-05-06 21:12:31 +03:00
|
|
|
"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
|
|
|
)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRemRangeByScore(key, min, max string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("zremrangebyscore", key, min, max)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRevRange(key string, start, stop int64) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringSliceCmd("zrevrange", key, start, stop)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewZSliceCmd("zrevrange", key, start, stop, "withscores")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2013-02-02 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) zRevRangeBy(zcmd, key string, opt ZRangeBy) *StringSliceCmd {
|
2015-08-25 22:15:01 +03:00
|
|
|
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,
|
2016-05-06 21:12:31 +03:00
|
|
|
"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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
return c.zRevRangeBy("zrevrangebyscore", key, opt)
|
2015-08-25 22:15:01 +03:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
return c.zRevRangeBy("zrevrangebylex", key, opt)
|
2015-08-25 22:15:01 +03:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
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,
|
2016-05-06 21:12:31 +03:00
|
|
|
"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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2013-02-02 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZRevRank(key, member string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("zrevrank", key, member)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZScore(key, member string) *FloatCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewFloatCmd("zscore", key, member)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 3+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "zunionstore"
|
2015-05-28 15:51:19 +03:00
|
|
|
args[1] = dest
|
|
|
|
args[2] = strconv.Itoa(len(keys))
|
|
|
|
for i, key := range keys {
|
|
|
|
args[3+i] = key
|
|
|
|
}
|
2012-08-17 22:36:48 +04:00
|
|
|
if len(store.Weights) > 0 {
|
2016-05-06 21:12:31 +03:00
|
|
|
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 != "" {
|
2016-05-06 21:12:31 +03:00
|
|
|
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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
2012-08-12 22:41:44 +04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) PFAdd(key string, els ...interface{}) *IntCmd {
|
2016-06-14 13:22:16 +03:00
|
|
|
args := make([]interface{}, 2+len(els))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "pfadd"
|
2015-11-04 10:34:58 +03:00
|
|
|
args[1] = key
|
2016-06-14 13:22:16 +03:00
|
|
|
for i, el := range els {
|
|
|
|
args[2+i] = el
|
2015-11-04 10:34:58 +03:00
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-11-04 10:34:58 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) PFCount(keys ...string) *IntCmd {
|
2015-12-24 01:24:42 +03:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "pfcount"
|
2015-12-24 01:24:42 +03:00
|
|
|
for i, key := range keys {
|
|
|
|
args[1+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-11-04 10:34:58 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) PFMerge(dest string, keys ...string) *StatusCmd {
|
2015-11-04 10:34:58 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
2016-05-06 21:12:31 +03:00
|
|
|
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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-11-04 10:34:58 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) BgRewriteAOF() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("bgrewriteaof")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) BgSave() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("bgsave")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClientKill(ipPort string) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("client", "kill", ipPort)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClientList() *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("client", "list")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2015-05-15 15:11:22 +03:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClientPause(dur time.Duration) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("client", "pause", formatMs(dur))
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-05-15 15:11:22 +03:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-10-22 14:15:47 +03:00
|
|
|
// ClientSetName assigns a name to the one of many connections in the pool.
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClientSetName(name string) *BoolCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewBoolCmd("client", "setname", name)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-10-20 22:21:58 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-10-22 14:15:47 +03:00
|
|
|
// ClientGetName returns the name of the one of many connections in the pool.
|
|
|
|
func (c *Client) ClientGetName() *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("client", "getname")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-10-20 22:21:58 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ConfigGet(parameter string) *SliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewSliceCmd("config", "get", parameter)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ConfigResetStat() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("config", "resetstat")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ConfigSet(parameter, value string) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("config", "set", parameter, value)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) DbSize() *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("dbsize")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) FlushAll() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("flushall")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) FlushDb() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("flushdb")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Info(section ...string) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
args := []interface{}{"info"}
|
2016-01-08 16:03:34 +03:00
|
|
|
if len(section) > 0 {
|
|
|
|
args = append(args, section[0])
|
|
|
|
}
|
|
|
|
cmd := NewStringCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) LastSave() *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("lastsave")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Save() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("save")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) shutdown(modifier string) *StatusCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
var args []interface{}
|
2012-08-25 16:35:39 +04:00
|
|
|
if modifier == "" {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = []interface{}{"shutdown"}
|
2012-08-25 16:35:39 +04:00
|
|
|
} else {
|
2016-05-06 21:12:31 +03:00
|
|
|
args = []interface{}{"shutdown", modifier}
|
2012-08-25 16:35:39 +04:00
|
|
|
}
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
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.
|
2016-07-02 15:52:10 +03:00
|
|
|
cmd.err = errors.RedisError(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
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Shutdown() *StatusCmd {
|
2012-08-25 16:35:39 +04:00
|
|
|
return c.shutdown("")
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ShutdownSave() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
return c.shutdown("save")
|
2012-08-25 16:35:39 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ShutdownNoSave() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
return c.shutdown("nosave")
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SlaveOf(host, port string) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("slaveof", host, port)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) SlowLog() {
|
2012-08-12 22:41:44 +04:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Sync() {
|
2012-08-12 22:41:44 +04:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Time() *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringSliceCmd("time")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
2012-08-20 14:42:33 +04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Eval(script string, keys []string, args ...interface{}) *Cmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
cmdArgs := make([]interface{}, 3+len(keys)+len(args))
|
2016-05-06 21:12:31 +03:00
|
|
|
cmdArgs[0] = "eval"
|
2015-05-28 15:51:19 +03:00
|
|
|
cmdArgs[1] = script
|
|
|
|
cmdArgs[2] = strconv.Itoa(len(keys))
|
|
|
|
for i, key := range keys {
|
|
|
|
cmdArgs[3+i] = key
|
|
|
|
}
|
|
|
|
pos := 3 + len(keys)
|
|
|
|
for i, arg := range args {
|
|
|
|
cmdArgs[pos+i] = arg
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewCmd(cmdArgs...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
cmdArgs := make([]interface{}, 3+len(keys)+len(args))
|
2016-05-06 21:12:31 +03:00
|
|
|
cmdArgs[0] = "evalsha"
|
2015-05-28 15:51:19 +03:00
|
|
|
cmdArgs[1] = sha1
|
|
|
|
cmdArgs[2] = strconv.Itoa(len(keys))
|
|
|
|
for i, key := range keys {
|
|
|
|
cmdArgs[3+i] = key
|
|
|
|
}
|
|
|
|
pos := 3 + len(keys)
|
|
|
|
for i, arg := range args {
|
|
|
|
cmdArgs[pos+i] = arg
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewCmd(cmdArgs...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ScriptExists(scripts ...string) *BoolSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(scripts))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "script"
|
|
|
|
args[1] = "exists"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, script := range scripts {
|
|
|
|
args[2+i] = script
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolSliceCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ScriptFlush() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("script", "flush")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ScriptKill() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("script", "kill")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ScriptLoad(script string) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("script", "load", script)
|
2016-06-05 12:45:39 +03:00
|
|
|
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
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) DebugObject(key string) *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("debug", "object", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
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
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) PubSubChannels(pattern string) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
args := []interface{}{"pubsub", "channels"}
|
2014-10-07 16:40:00 +04:00
|
|
|
if pattern != "*" {
|
|
|
|
args = append(args, pattern)
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-10-07 14:06:41 +04:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) PubSubNumSub(channels ...string) *StringIntMapCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(channels))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "pubsub"
|
|
|
|
args[1] = "numsub"
|
2015-05-28 15:51:19 +03:00
|
|
|
for i, channel := range channels {
|
|
|
|
args[2+i] = channel
|
|
|
|
}
|
2015-01-25 15:05:19 +03:00
|
|
|
cmd := NewStringIntMapCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-10-07 14:06:41 +04:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) PubSubNumPat() *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("pubsub", "numpat")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-01-24 15:12:48 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterSlots() *ClusterSlotsCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewClusterSlotsCmd("cluster", "slots")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-01-24 15:12:48 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterNodes() *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("cluster", "nodes")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-01-24 15:12:48 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterMeet(host, port string) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("cluster", "meet", host, port)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2014-10-07 14:06:41 +04:00
|
|
|
return cmd
|
|
|
|
}
|
2015-01-24 15:12:48 +03:00
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterForget(nodeID string) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("cluster", "forget", nodeID)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-12-09 12:33:37 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterReplicate(nodeID string) *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("cluster", "replicate", nodeID)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-01-24 15:12:48 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterResetSoft() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("cluster", "reset", "soft")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-12-21 19:53:02 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterResetHard() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("cluster", "reset", "hard")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-12-21 19:53:02 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterInfo() *StringCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringCmd("cluster", "info")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-01-24 15:12:48 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterKeySlot(key string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("cluster", "keyslot", key)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-12-28 19:58:04 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterCountFailureReports(nodeID string) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("cluster", "count-failure-reports", nodeID)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-12-29 19:16:14 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterCountKeysInSlot(slot int) *IntCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewIntCmd("cluster", "countkeysinslot", slot)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-12-29 19:16:14 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterDelSlots(slots ...int) *StatusCmd {
|
2015-12-29 19:16:14 +03:00
|
|
|
args := make([]interface{}, 2+len(slots))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "cluster"
|
|
|
|
args[1] = "delslots"
|
2015-12-29 19:16:14 +03:00
|
|
|
for i, slot := range slots {
|
|
|
|
args[2+i] = slot
|
|
|
|
}
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-12-29 19:16:14 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterDelSlotsRange(min, max int) *StatusCmd {
|
2015-12-29 19:16:14 +03:00
|
|
|
size := max - min + 1
|
|
|
|
slots := make([]int, size)
|
|
|
|
for i := 0; i < size; i++ {
|
|
|
|
slots[i] = min + i
|
|
|
|
}
|
|
|
|
return c.ClusterDelSlots(slots...)
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterSaveConfig() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("cluster", "saveconfig")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-12-29 19:16:14 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterSlaves(nodeID string) *StringSliceCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStringSliceCmd("cluster", "slaves", nodeID)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-12-29 19:16:14 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *statefulCmdable) ReadOnly() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("readonly")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-12-29 19:16:14 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *statefulCmdable) ReadWrite() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("readwrite")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-12-29 19:16:14 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterFailover() *StatusCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd("cluster", "failover")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-01-24 15:12:48 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) ClusterAddSlots(slots ...int) *StatusCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(slots))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "cluster"
|
|
|
|
args[1] = "addslots"
|
2015-01-24 15:12:48 +03:00
|
|
|
for i, num := range slots {
|
2015-05-28 15:51:19 +03:00
|
|
|
args[2+i] = strconv.Itoa(num)
|
2015-01-24 15:12:48 +03:00
|
|
|
}
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewStatusCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-01-24 15:12:48 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
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...)
|
|
|
|
}
|
2015-09-20 16:13:13 +03:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd {
|
2015-09-20 16:13:13 +03:00
|
|
|
args := make([]interface{}, 2+3*len(geoLocation))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "geoadd"
|
2015-09-20 16:13:13 +03:00
|
|
|
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...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-09-20 16:13:13 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewGeoLocationCmd(query, "georadius", key, longitude, latitude)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-09-20 16:13:13 +03:00
|
|
|
return cmd
|
|
|
|
}
|
2015-10-15 00:39:39 +03:00
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewGeoLocationCmd(query, "georadiusbymember", key, member)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-11-14 17:36:21 +03:00
|
|
|
return cmd
|
2015-10-15 00:39:39 +03:00
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) GeoDist(key string, member1, member2, unit string) *FloatCmd {
|
2015-10-15 00:39:39 +03:00
|
|
|
if unit == "" {
|
|
|
|
unit = "km"
|
|
|
|
}
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewFloatCmd("geodist", key, member1, member2, unit)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-10-15 00:39:39 +03:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) GeoHash(key string, members ...string) *StringSliceCmd {
|
2015-10-15 00:39:39 +03:00
|
|
|
args := make([]interface{}, 2+len(members))
|
2016-05-06 21:12:31 +03:00
|
|
|
args[0] = "geohash"
|
2015-10-15 00:39:39 +03:00
|
|
|
args[1] = key
|
|
|
|
for i, member := range members {
|
|
|
|
args[2+i] = member
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2015-10-15 00:39:39 +03:00
|
|
|
return cmd
|
|
|
|
}
|
2016-05-06 21:12:31 +03:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-07-01 15:25:28 +03:00
|
|
|
func (c *cmdable) Command() *CommandsInfoCmd {
|
2016-05-06 21:12:31 +03:00
|
|
|
cmd := NewCommandsInfoCmd("command")
|
2016-06-05 12:45:39 +03:00
|
|
|
c.process(cmd)
|
2016-05-06 21:12:31 +03:00
|
|
|
return cmd
|
|
|
|
}
|