2012-07-25 17:00:50 +04:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
2014-11-13 15:26:14 +03:00
|
|
|
"io"
|
2015-04-07 12:42:16 +03:00
|
|
|
"log"
|
2012-07-25 17:00:50 +04:00
|
|
|
"strconv"
|
2014-05-11 11:42:40 +04:00
|
|
|
"time"
|
2012-07-25 17:00:50 +04:00
|
|
|
)
|
|
|
|
|
2015-03-30 16:14:21 +03:00
|
|
|
func formatInt(i int64) string {
|
|
|
|
return strconv.FormatInt(i, 10)
|
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func formatUint(i uint64) string {
|
|
|
|
return strconv.FormatUint(i, 10)
|
|
|
|
}
|
|
|
|
|
|
|
|
func formatFloat(f float64) string {
|
|
|
|
return strconv.FormatFloat(f, 'f', -1, 64)
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
log.Printf(
|
|
|
|
"redis: specified duration is %s, but minimal supported value is %s",
|
|
|
|
dur, time.Millisecond,
|
|
|
|
)
|
|
|
|
}
|
2015-05-28 15:51:19 +03:00
|
|
|
return formatInt(int64(dur / time.Millisecond))
|
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 {
|
|
|
|
log.Printf(
|
|
|
|
"redis: specified duration is %s, but minimal supported value is %s",
|
|
|
|
dur, time.Second,
|
|
|
|
)
|
|
|
|
}
|
2015-05-28 15:51:19 +03:00
|
|
|
return formatInt(int64(dur / time.Second))
|
|
|
|
}
|
|
|
|
|
|
|
|
type commandable struct {
|
|
|
|
process func(cmd Cmder)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandable) Process(cmd Cmder) {
|
|
|
|
c.process(cmd)
|
2015-01-31 12:08:56 +03:00
|
|
|
}
|
|
|
|
|
2012-07-27 18:21:50 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Auth(password string) *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("AUTH", password)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Echo(message string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("ECHO", message)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Ping() *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("PING")
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Quit() *StatusCmd {
|
2012-08-25 16:40:49 +04:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Select(index int64) *StatusCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := newKeylessStatusCmd("SELECT", index)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Del(keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 1+len(keys))
|
|
|
|
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)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Dump(key string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("DUMP", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Exists(key string) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("EXISTS", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
func (c *commandable) Expire(key string, expiration time.Duration) *BoolCmd {
|
|
|
|
cmd := NewBoolCmd("EXPIRE", key, formatSec(expiration))
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ExpireAt(key string, tm time.Time) *BoolCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewBoolCmd("EXPIREAT", key, tm.Unix())
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Keys(pattern string) *StringSliceCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd("KEYS", pattern)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-04-07 12:42:16 +03:00
|
|
|
func (c *commandable) Migrate(host, port, key string, db int64, timeout time.Duration) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(
|
2012-07-26 19:16:17 +04:00
|
|
|
"MIGRATE",
|
|
|
|
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
|
|
|
)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 3
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd.setReadTimeout(readTimeout(timeout))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Move(key string, db int64) *BoolCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewBoolCmd("MOVE", key, db)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ObjectRefCount(keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
|
|
|
args[0] = "OBJECT"
|
|
|
|
args[1] = "REFCOUNT"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 2
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ObjectEncoding(keys ...string) *StringCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
|
|
|
args[0] = "OBJECT"
|
|
|
|
args[1] = "ENCODING"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd(args...)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 2
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ObjectIdleTime(keys ...string) *DurationCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
|
|
|
args[0] = "OBJECT"
|
|
|
|
args[1] = "IDLETIME"
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewDurationCmd(time.Second, args...)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 2
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Persist(key string) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("PERSIST", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-31 12:08:56 +03:00
|
|
|
func (c *commandable) PExpire(key string, expiration time.Duration) *BoolCmd {
|
|
|
|
cmd := NewBoolCmd("PEXPIRE", key, formatMs(expiration))
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) PExpireAt(key string, tm time.Time) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd(
|
2014-05-11 11:42:40 +04:00
|
|
|
"PEXPIREAT",
|
|
|
|
key,
|
2015-10-07 18:21:18 +03:00
|
|
|
tm.UnixNano()/int64(time.Millisecond),
|
2014-05-11 11:42:40 +04:00
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) PTTL(key string) *DurationCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewDurationCmd(time.Millisecond, "PTTL", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) RandomKey() *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("RANDOMKEY")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Rename(key, newkey string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("RENAME", key, newkey)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) RenameNX(key, newkey string) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("RENAMENX", key, newkey)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-07-11 12:10:41 +03:00
|
|
|
func (c *commandable) Restore(key string, ttl time.Duration, value string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(
|
2012-07-26 19:16:17 +04: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,
|
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-07-11 12:23:04 +03:00
|
|
|
func (c *commandable) RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd {
|
|
|
|
cmd := NewStatusCmd(
|
|
|
|
"RESTORE",
|
|
|
|
key,
|
|
|
|
formatMs(ttl),
|
|
|
|
value,
|
|
|
|
"REPLACE",
|
|
|
|
)
|
|
|
|
c.Process(cmd)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Sort(key string, sort Sort) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := []interface{}{"SORT", key}
|
2012-08-17 22:36:48 +04:00
|
|
|
if sort.By != "" {
|
2014-12-09 13:41:03 +03:00
|
|
|
args = append(args, "BY", sort.By)
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
|
|
|
if sort.Offset != 0 || sort.Count != 0 {
|
2015-10-07 18:21:18 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
if sort.Order != "" {
|
|
|
|
args = append(args, sort.Order)
|
|
|
|
}
|
|
|
|
if sort.IsAlpha {
|
|
|
|
args = append(args, "ALPHA")
|
|
|
|
}
|
|
|
|
if sort.Store != "" {
|
|
|
|
args = append(args, "STORE", sort.Store)
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) TTL(key string) *DurationCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewDurationCmd(time.Second, "TTL", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Type(key string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("TYPE", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Scan(cursor int64, match string, count int64) *ScanCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
args := []interface{}{"SCAN", cursor}
|
2014-05-11 11:42:40 +04:00
|
|
|
if match != "" {
|
|
|
|
args = append(args, "MATCH", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
2015-10-07 18:21:18 +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...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SScan(key string, cursor int64, match string, count int64) *ScanCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
args := []interface{}{"SSCAN", key, cursor}
|
2014-05-11 11:42:40 +04:00
|
|
|
if match != "" {
|
|
|
|
args = append(args, "MATCH", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
2015-10-07 18:21:18 +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...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HScan(key string, cursor int64, match string, count int64) *ScanCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
args := []interface{}{"HSCAN", key, cursor}
|
2014-05-11 11:42:40 +04:00
|
|
|
if match != "" {
|
|
|
|
args = append(args, "MATCH", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
2015-10-07 18:21:18 +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...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZScan(key string, cursor int64, match string, count int64) *ScanCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
args := []interface{}{"ZSCAN", key, cursor}
|
2014-05-11 11:42:40 +04:00
|
|
|
if match != "" {
|
|
|
|
args = append(args, "MATCH", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
2015-10-07 18:21:18 +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...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Append(key, value string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("APPEND", key, value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
type BitCount struct {
|
|
|
|
Start, End int64
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) BitCount(key string, bitCount *BitCount) *IntCmd {
|
2015-05-28 15:51:19 +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...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-19 16:57:58 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) bitOp(op, destKey string, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 3+len(keys))
|
|
|
|
args[0] = "BITOP"
|
|
|
|
args[1] = op
|
|
|
|
args[2] = destKey
|
|
|
|
for i, key := range keys {
|
|
|
|
args[3+i] = key
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-19 16:57:58 +04:00
|
|
|
}
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) BitOpAnd(destKey string, keys ...string) *IntCmd {
|
2012-08-19 16:57:58 +04:00
|
|
|
return c.bitOp("AND", destKey, keys...)
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) BitOpOr(destKey string, keys ...string) *IntCmd {
|
2012-08-19 16:57:58 +04:00
|
|
|
return c.bitOp("OR", destKey, keys...)
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) BitOpXor(destKey string, keys ...string) *IntCmd {
|
2012-08-19 16:57:58 +04:00
|
|
|
return c.bitOp("XOR", destKey, keys...)
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) BitOpNot(destKey string, key string) *IntCmd {
|
2012-08-19 16:57:58 +04:00
|
|
|
return c.bitOp("NOT", destKey, key)
|
|
|
|
}
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2014-10-07 14:54:43 +04:00
|
|
|
func (c *commandable) BitPos(key string, bit int64, pos ...int64) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
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)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Decr(key string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("DECR", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) DecrBy(key string, decrement int64) *IntCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewIntCmd("DECRBY", key, decrement)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Get(key string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("GET", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) GetBit(key string, offset int64) *IntCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewIntCmd("GETBIT", key, offset)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) GetRange(key string, start, end int64) *StringCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewStringCmd("GETRANGE", key, start, end)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:51:19 +03:00
|
|
|
func (c *commandable) GetSet(key string, value interface{}) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("GETSET", key, value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Incr(key string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("INCR", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) IncrBy(key string, value int64) *IntCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewIntCmd("INCRBY", key, value)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) IncrByFloat(key string, value float64) *FloatCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewFloatCmd("INCRBYFLOAT", key, value)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-19 16:57:58 +04:00
|
|
|
}
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) MGet(keys ...string) *SliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
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)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) MSet(pairs ...string) *StatusCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 1+len(pairs))
|
|
|
|
args[0] = "MSET"
|
|
|
|
for i, pair := range pairs {
|
|
|
|
args[1+i] = pair
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) MSetNX(pairs ...string) *BoolCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 1+len(pairs))
|
|
|
|
args[0] = "MSETNX"
|
|
|
|
for i, pair := range pairs {
|
|
|
|
args[1+i] = pair
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
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.
|
2015-05-28 15:51:19 +03:00
|
|
|
func (c *commandable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd {
|
|
|
|
args := make([]interface{}, 3, 5)
|
|
|
|
args[0] = "SET"
|
|
|
|
args[1] = key
|
|
|
|
args[2] = value
|
2015-01-31 12:08:56 +03:00
|
|
|
if expiration > 0 {
|
|
|
|
if usePrecise(expiration) {
|
|
|
|
args = append(args, "PX", formatMs(expiration))
|
|
|
|
} else {
|
|
|
|
args = append(args, "EX", formatSec(expiration))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd := NewStatusCmd(args...)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) 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
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
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.
|
2015-05-28 15:51:19 +03:00
|
|
|
func (c *commandable) 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.
|
|
|
|
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.
|
2015-05-28 15:51:19 +03:00
|
|
|
func (c *Client) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd {
|
2015-01-31 12:08:56 +03:00
|
|
|
var cmd *BoolCmd
|
|
|
|
if usePrecise(expiration) {
|
|
|
|
cmd = NewBoolCmd("SET", key, value, "PX", formatMs(expiration), "XX")
|
|
|
|
} else {
|
|
|
|
cmd = NewBoolCmd("SET", key, value, "EX", formatSec(expiration), "XX")
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SetRange(key string, offset int64, value string) *IntCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewIntCmd("SETRANGE", key, offset, value)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) StrLen(key string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("STRLEN", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HDel(key string, fields ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
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)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HExists(key, field string) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("HEXISTS", key, field)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HGet(key, field string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("HGET", key, field)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HGetAll(key string) *StringSliceCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd("HGETALL", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HGetAllMap(key string) *StringStringMapCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringStringMapCmd("HGETALL", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2013-02-02 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HIncrBy(key, field string, incr int64) *IntCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewIntCmd("HINCRBY", key, field, incr)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HIncrByFloat(key, field string, incr float64) *FloatCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewFloatCmd("HINCRBYFLOAT", key, field, incr)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HKeys(key string) *StringSliceCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd("HKEYS", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HLen(key string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("HLEN", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HMGet(key string, fields ...string) *SliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
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)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HMSet(key, field, value string, pairs ...string) *StatusCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 4+len(pairs))
|
|
|
|
args[0] = "HMSET"
|
|
|
|
args[1] = key
|
|
|
|
args[2] = field
|
|
|
|
args[3] = value
|
|
|
|
for i, pair := range pairs {
|
|
|
|
args[4+i] = pair
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HSet(key, field, value string) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("HSET", key, field, value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HSetNX(key, field, value string) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("HSETNX", key, field, value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) HVals(key string) *StringSliceCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd("HVALS", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2012-07-26 19:16:17 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-04-07 12:42:16 +03:00
|
|
|
func (c *commandable) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
|
|
|
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(readTimeout(timeout))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-04-07 12:42:16 +03:00
|
|
|
func (c *commandable) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(keys))
|
|
|
|
args[0] = "BRPOP"
|
|
|
|
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))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-04-07 12:42:16 +03:00
|
|
|
func (c *commandable) BRPopLPush(source, destination string, timeout time.Duration) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd(
|
2012-07-26 19:16:17 +04:00
|
|
|
"BRPOPLPUSH",
|
|
|
|
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))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) LIndex(key string, index int64) *StringCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewStringCmd("LINDEX", key, index)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) LInsert(key, op, pivot, value string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("LINSERT", key, op, pivot, value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) LLen(key string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("LLEN", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) LPop(key string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("LPOP", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-12-12 18:41:49 +03:00
|
|
|
func (c *commandable) LPush(key string, values ...string) *IntCmd {
|
|
|
|
args := make([]interface{}, 2+len(values))
|
2015-05-28 15:51:19 +03:00
|
|
|
args[0] = "LPUSH"
|
|
|
|
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...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-12-12 19:52:23 +03:00
|
|
|
func (c *commandable) LPushX(key, value interface{}) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("LPUSHX", key, value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) LRange(key string, start, stop int64) *StringSliceCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(
|
2012-07-26 19:16:17 +04:00
|
|
|
"LRANGE",
|
|
|
|
key,
|
2015-10-07 18:21:18 +03:00
|
|
|
start,
|
|
|
|
stop,
|
2012-07-26 19:16:17 +04:00
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-12-12 19:52:23 +03:00
|
|
|
func (c *commandable) LRem(key string, count int64, value interface{}) *IntCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewIntCmd("LREM", key, count, value)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-12-12 19:52:23 +03:00
|
|
|
func (c *commandable) LSet(key string, index int64, value interface{}) *StatusCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewStatusCmd("LSET", key, index, value)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) LTrim(key string, start, stop int64) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(
|
2012-07-26 19:16:17 +04:00
|
|
|
"LTRIM",
|
|
|
|
key,
|
2015-10-07 18:21:18 +03:00
|
|
|
start,
|
|
|
|
stop,
|
2012-07-26 19:16:17 +04:00
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) RPop(key string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("RPOP", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) RPopLPush(source, destination string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("RPOPLPUSH", source, destination)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-12-12 18:41:49 +03:00
|
|
|
func (c *commandable) RPush(key string, values ...string) *IntCmd {
|
|
|
|
args := make([]interface{}, 2+len(values))
|
2015-05-28 15:51:19 +03:00
|
|
|
args[0] = "RPUSH"
|
|
|
|
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...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-12-12 19:52:23 +03:00
|
|
|
func (c *commandable) RPushX(key string, value interface{}) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("RPUSHX", key, value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-12-12 18:41:49 +03:00
|
|
|
func (c *commandable) SAdd(key string, members ...string) *IntCmd {
|
|
|
|
args := make([]interface{}, 2+len(members))
|
2015-05-28 15:51:19 +03:00
|
|
|
args[0] = "SADD"
|
|
|
|
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...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SCard(key string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("SCARD", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SDiff(keys ...string) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
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)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SDiffStore(destination string, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
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)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SInter(keys ...string) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
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)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SInterStore(destination string, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
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)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-12-12 19:52:23 +03:00
|
|
|
func (c *commandable) SIsMember(key string, member interface{}) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("SISMEMBER", key, member)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SMembers(key string) *StringSliceCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd("SMEMBERS", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-12-12 19:52:23 +03:00
|
|
|
func (c *commandable) SMove(source, destination string, member interface{}) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("SMOVE", source, destination, member)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SPop(key string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("SPOP", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-08-25 14:02:16 +03:00
|
|
|
// Redis `SRANDMEMBER key` command.
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SRandMember(key string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("SRANDMEMBER", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
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 *commandable) SRandMemberN(key string, count int64) *StringSliceCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewStringSliceCmd("SRANDMEMBER", key, count)
|
2015-08-25 14:02:16 +03:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-12-12 18:41:49 +03:00
|
|
|
func (c *commandable) SRem(key string, members ...string) *IntCmd {
|
|
|
|
args := make([]interface{}, 2+len(members))
|
2015-05-28 15:51:19 +03:00
|
|
|
args[0] = "SREM"
|
|
|
|
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...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SUnion(keys ...string) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
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)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SUnionStore(destination string, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
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)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-08-29 13:08:27 +03:00
|
|
|
func (c *commandable) zAdd(a []interface{}, n int, members ...Z) *IntCmd {
|
|
|
|
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)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key score member [score member ...]` command.
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) 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
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key NX score member [score member ...]` command.
|
|
|
|
func (c *commandable) ZAddNX(key string, members ...Z) *IntCmd {
|
|
|
|
const n = 3
|
|
|
|
a := make([]interface{}, n+2*len(members))
|
|
|
|
a[0], a[1], a[2] = "ZADD", key, "NX"
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key XX score member [score member ...]` command.
|
|
|
|
func (c *commandable) ZAddXX(key string, members ...Z) *IntCmd {
|
|
|
|
const n = 3
|
|
|
|
a := make([]interface{}, n+2*len(members))
|
|
|
|
a[0], a[1], a[2] = "ZADD", key, "XX"
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key CH score member [score member ...]` command.
|
|
|
|
func (c *commandable) ZAddCh(key string, members ...Z) *IntCmd {
|
|
|
|
const n = 3
|
|
|
|
a := make([]interface{}, n+2*len(members))
|
|
|
|
a[0], a[1], a[2] = "ZADD", key, "CH"
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key NX CH score member [score member ...]` command.
|
|
|
|
func (c *commandable) ZAddNXCh(key string, members ...Z) *IntCmd {
|
|
|
|
const n = 4
|
|
|
|
a := make([]interface{}, n+2*len(members))
|
|
|
|
a[0], a[1], a[2], a[3] = "ZADD", key, "NX", "CH"
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key XX CH score member [score member ...]` command.
|
|
|
|
func (c *commandable) ZAddXXCh(key string, members ...Z) *IntCmd {
|
|
|
|
const n = 4
|
|
|
|
a := make([]interface{}, n+2*len(members))
|
|
|
|
a[0], a[1], a[2], a[3] = "ZADD", key, "XX", "CH"
|
|
|
|
return c.zAdd(a, n, members...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandable) 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...)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
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 *commandable) ZIncr(key string, member Z) *FloatCmd {
|
|
|
|
const n = 3
|
|
|
|
a := make([]interface{}, n+2)
|
|
|
|
a[0], a[1], a[2] = "ZADD", key, "INCR"
|
|
|
|
return c.zIncr(a, n, member)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key NX INCR score member` command.
|
|
|
|
func (c *commandable) ZIncrNX(key string, member Z) *FloatCmd {
|
|
|
|
const n = 4
|
|
|
|
a := make([]interface{}, n+2)
|
|
|
|
a[0], a[1], a[2], a[3] = "ZADD", key, "INCR", "NX"
|
|
|
|
return c.zIncr(a, n, member)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redis `ZADD key XX INCR score member` command.
|
|
|
|
func (c *commandable) ZIncrXX(key string, member Z) *FloatCmd {
|
|
|
|
const n = 4
|
|
|
|
a := make([]interface{}, n+2)
|
|
|
|
a[0], a[1], a[2], a[3] = "ZADD", key, "INCR", "XX"
|
|
|
|
return c.zIncr(a, n, member)
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZCard(key string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("ZCARD", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZCount(key, min, max string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("ZCOUNT", key, min, max)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZIncrBy(key string, increment float64, member string) *FloatCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewFloatCmd("ZINCRBY", key, increment, member)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-12-01 17:28:41 +03:00
|
|
|
func (c *commandable) ZInterStore(destination string, store ZStore, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 3+len(keys))
|
|
|
|
args[0] = "ZINTERSTORE"
|
|
|
|
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 {
|
2012-07-27 18:21:50 +04: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 != "" {
|
|
|
|
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)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) zRange(key string, start, stop int64, withScores bool) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := []interface{}{
|
2012-07-27 18:21:50 +04:00
|
|
|
"ZRANGE",
|
|
|
|
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")
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZRange(key string, start, stop int64) *StringSliceCmd {
|
2012-08-17 22:36:48 +04:00
|
|
|
return c.zRange(key, start, stop, false)
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewZSliceCmd("ZRANGE", key, start, stop, "WITHSCORES")
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2013-02-02 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2015-08-25 22:15:01 +03:00
|
|
|
// TODO: Rename to something more generic in v4
|
|
|
|
type ZRangeByScore struct {
|
2015-03-30 16:14:21 +03:00
|
|
|
Min, Max string
|
2014-05-11 11:42:40 +04:00
|
|
|
Offset, Count int64
|
|
|
|
}
|
|
|
|
|
2015-08-25 22:15:01 +03:00
|
|
|
func (c *commandable) zRangeBy(zcmd, key string, opt ZRangeByScore, 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")
|
|
|
|
}
|
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)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-08-25 22:15:01 +03:00
|
|
|
func (c *commandable) ZRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd {
|
2015-08-25 00:52:00 +03:00
|
|
|
return c.zRangeBy("ZRANGEBYSCORE", key, opt, false)
|
2015-08-23 06:38:37 +03:00
|
|
|
}
|
|
|
|
|
2015-08-25 22:15:01 +03:00
|
|
|
func (c *commandable) ZRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd {
|
2015-08-25 00:52:00 +03:00
|
|
|
return c.zRangeBy("ZRANGEBYLEX", key, opt, false)
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
|
|
|
|
2015-08-25 22:15:01 +03:00
|
|
|
func (c *commandable) ZRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd {
|
2015-05-28 15:51:19 +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,
|
|
|
|
"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...)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2013-02-02 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZRank(key, member string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("ZRANK", key, member)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZRem(key string, members ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(members))
|
|
|
|
args[0] = "ZREM"
|
|
|
|
args[1] = key
|
|
|
|
for i, member := range members {
|
|
|
|
args[2+i] = member
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZRemRangeByRank(key string, start, stop int64) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(
|
2012-07-27 18:21:50 +04:00
|
|
|
"ZREMRANGEBYRANK",
|
|
|
|
key,
|
2015-10-07 18:21:18 +03:00
|
|
|
start,
|
|
|
|
stop,
|
2012-07-27 18:21:50 +04:00
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZRemRangeByScore(key, min, max string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("ZREMRANGEBYSCORE", key, min, max)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-03-30 16:14:21 +03:00
|
|
|
func (c *commandable) ZRevRange(key string, start, stop int64) *StringSliceCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewStringSliceCmd("ZREVRANGE", key, start, stop)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-03-30 16:14:21 +03:00
|
|
|
func (c *commandable) ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd {
|
2015-10-07 18:21:18 +03:00
|
|
|
cmd := NewZSliceCmd("ZREVRANGE", key, start, stop, "WITHSCORES")
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2013-02-02 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2015-08-25 22:15:01 +03:00
|
|
|
func (c *commandable) zRevRangeBy(zcmd, key string, opt ZRangeByScore) *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)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-08-25 22:15:01 +03:00
|
|
|
func (c *commandable) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd {
|
|
|
|
return c.zRevRangeBy("ZREVRANGEBYSCORE", key, opt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c commandable) ZRevRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd {
|
|
|
|
return c.zRevRangeBy("ZREVRANGEBYLEX", key, opt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandable) ZRevRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd {
|
2015-05-28 15:51:19 +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,
|
|
|
|
"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...)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2013-02-02 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZRevRank(key, member string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("ZREVRANK", key, member)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ZScore(key, member string) *FloatCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewFloatCmd("ZSCORE", key, member)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2015-03-30 16:14:21 +03:00
|
|
|
func (c *commandable) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 3+len(keys))
|
|
|
|
args[0] = "ZUNIONSTORE"
|
|
|
|
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 {
|
2012-07-27 18:21:50 +04: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 != "" {
|
|
|
|
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)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
2012-08-12 22:41:44 +04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-11-04 10:34:58 +03:00
|
|
|
func (c *commandable) PFAdd(key string, fields ...string) *IntCmd {
|
|
|
|
args := make([]interface{}, 2+len(fields))
|
|
|
|
args[0] = "PFADD"
|
|
|
|
args[1] = key
|
|
|
|
for i, field := range fields {
|
|
|
|
args[2+i] = field
|
|
|
|
}
|
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-12-24 01:24:42 +03:00
|
|
|
func (c *commandable) 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...)
|
2015-11-04 10:34:58 +03:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandable) PFMerge(dest string, keys ...string) *StatusCmd {
|
|
|
|
args := make([]interface{}, 2+len(keys))
|
|
|
|
args[0] = "PFMERGE"
|
|
|
|
args[1] = dest
|
|
|
|
for i, key := range keys {
|
|
|
|
args[2+i] = key
|
|
|
|
}
|
|
|
|
cmd := NewStatusCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) BgRewriteAOF() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("BGREWRITEAOF")
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) BgSave() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("BGSAVE")
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ClientKill(ipPort string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("CLIENT", "KILL", ipPort)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ClientList() *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("CLIENT", "LIST")
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2015-05-15 15:11:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandable) ClientPause(dur time.Duration) *BoolCmd {
|
|
|
|
cmd := NewBoolCmd("CLIENT", "PAUSE", formatMs(dur))
|
|
|
|
cmd._clusterKeyPos = 0
|
|
|
|
c.Process(cmd)
|
|
|
|
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.
|
|
|
|
func (c *commandable) ClientSetName(name string) *BoolCmd {
|
|
|
|
cmd := NewBoolCmd("CLIENT", "SETNAME", name)
|
2015-10-20 22:21:58 +03:00
|
|
|
c.Process(cmd)
|
|
|
|
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 {
|
2015-10-20 22:21:58 +03:00
|
|
|
cmd := NewStringCmd("CLIENT", "GETNAME")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ConfigGet(parameter string) *SliceCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewSliceCmd("CONFIG", "GET", parameter)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ConfigResetStat() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("CONFIG", "RESETSTAT")
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ConfigSet(parameter, value string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("CONFIG", "SET", parameter, value)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) DbSize() *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("DBSIZE")
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) FlushAll() *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("FLUSHALL")
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) FlushDb() *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("FLUSHDB")
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Info() *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("INFO")
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) LastSave() *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("LASTSAVE")
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Save() *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("SAVE")
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) 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 == "" {
|
2015-05-28 15:51:19 +03:00
|
|
|
args = []interface{}{"SHUTDOWN"}
|
2012-08-25 16:35:39 +04:00
|
|
|
} else {
|
2015-05-28 15:51:19 +03:00
|
|
|
args = []interface{}{"SHUTDOWN", modifier}
|
2012-08-25 16:35:39 +04:00
|
|
|
}
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd := newKeylessStatusCmd(args...)
|
2014-06-25 11:40:56 +04: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.
|
|
|
|
cmd.err = errorf(cmd.val)
|
|
|
|
cmd.val = ""
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-25 16:35:39 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Shutdown() *StatusCmd {
|
2012-08-25 16:35:39 +04:00
|
|
|
return c.shutdown("")
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ShutdownSave() *StatusCmd {
|
2012-08-25 16:35:39 +04:00
|
|
|
return c.shutdown("SAVE")
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ShutdownNoSave() *StatusCmd {
|
2012-08-25 16:35:39 +04:00
|
|
|
return c.shutdown("NOSAVE")
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SlaveOf(host, port string) *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("SLAVEOF", host, port)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) SlowLog() {
|
2012-08-12 22:41:44 +04:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Sync() {
|
2012-08-12 22:41:44 +04:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Time() *StringSliceCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd("TIME")
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
2012-08-20 14:42:33 +04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) Eval(script string, keys []string, args []string) *Cmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
cmdArgs := make([]interface{}, 3+len(keys)+len(args))
|
|
|
|
cmdArgs[0] = "EVAL"
|
|
|
|
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...)
|
2015-01-24 15:12:48 +03:00
|
|
|
if len(keys) > 0 {
|
|
|
|
cmd._clusterKeyPos = 3
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) EvalSha(sha1 string, keys []string, args []string) *Cmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
cmdArgs := make([]interface{}, 3+len(keys)+len(args))
|
|
|
|
cmdArgs[0] = "EVALSHA"
|
|
|
|
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...)
|
2015-01-24 15:12:48 +03:00
|
|
|
if len(keys) > 0 {
|
|
|
|
cmd._clusterKeyPos = 3
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ScriptExists(scripts ...string) *BoolSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(scripts))
|
|
|
|
args[0] = "SCRIPT"
|
|
|
|
args[1] = "EXISTS"
|
|
|
|
for i, script := range scripts {
|
|
|
|
args[2+i] = script
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolSliceCmd(args...)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ScriptFlush() *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("SCRIPT", "FLUSH")
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ScriptKill() *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("SCRIPT", "KILL")
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ScriptLoad(script string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("SCRIPT", "LOAD", script)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) DebugObject(key string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("DEBUG", "OBJECT", key)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 2
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
2014-10-07 14:06:41 +04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) PubSubChannels(pattern string) *StringSliceCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := []interface{}{"PUBSUB", "CHANNELS"}
|
2014-10-07 16:40:00 +04:00
|
|
|
if pattern != "*" {
|
|
|
|
args = append(args, pattern)
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-10-07 14:06:41 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) PubSubNumSub(channels ...string) *StringIntMapCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
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...)
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
2014-10-07 14:06:41 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) PubSubNumPat() *IntCmd {
|
2014-10-07 14:06:41 +04:00
|
|
|
cmd := NewIntCmd("PUBSUB", "NUMPAT")
|
2015-01-24 15:12:48 +03:00
|
|
|
cmd._clusterKeyPos = 0
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func (c *commandable) ClusterSlots() *ClusterSlotCmd {
|
|
|
|
cmd := NewClusterSlotCmd("CLUSTER", "slots")
|
|
|
|
cmd._clusterKeyPos = 0
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandable) ClusterNodes() *StringCmd {
|
|
|
|
cmd := NewStringCmd("CLUSTER", "nodes")
|
|
|
|
cmd._clusterKeyPos = 0
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandable) ClusterMeet(host, port string) *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("CLUSTER", "meet", host, port)
|
2014-10-07 14:06:41 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
2015-01-24 15:12:48 +03:00
|
|
|
|
2015-12-09 12:33:37 +03:00
|
|
|
func (c *commandable) ClusterForget(nodeID string) *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("CLUSTER", "forget", nodeID)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ClusterReplicate(nodeID string) *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("CLUSTER", "replicate", nodeID)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-12-21 19:53:02 +03:00
|
|
|
func (c *commandable) ClusterResetSoft() *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("CLUSTER", "reset", "soft")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandable) ClusterResetHard() *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("CLUSTER", "reset", "hard")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ClusterInfo() *StringCmd {
|
|
|
|
cmd := NewStringCmd("CLUSTER", "info")
|
|
|
|
cmd._clusterKeyPos = 0
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-12-28 19:58:04 +03:00
|
|
|
func (c *commandable) ClusterKeySlot(key string) *IntCmd {
|
|
|
|
cmd := NewIntCmd("CLUSTER", "keyslot", key)
|
|
|
|
cmd._clusterKeyPos = 2
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-01-24 15:12:48 +03:00
|
|
|
func (c *commandable) ClusterFailover() *StatusCmd {
|
|
|
|
cmd := newKeylessStatusCmd("CLUSTER", "failover")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandable) ClusterAddSlots(slots ...int) *StatusCmd {
|
2015-05-28 15:51:19 +03:00
|
|
|
args := make([]interface{}, 2+len(slots))
|
2015-01-24 15:12:48 +03:00
|
|
|
args[0] = "CLUSTER"
|
2015-05-28 15:51:19 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
cmd := newKeylessStatusCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandable) ClusterAddSlotsRange(min, max int) *StatusCmd {
|
|
|
|
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
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func (c *commandable) 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
|
|
|
|
}
|
|
|
|
|
2015-11-14 17:36:21 +03:00
|
|
|
func (c *commandable) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd {
|
|
|
|
cmd := NewGeoLocationCmd(query, "GEORADIUS", key, longitude, latitude)
|
2015-09-20 16:13:13 +03:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
2015-10-15 00:39:39 +03:00
|
|
|
|
|
|
|
func (c *commandable) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd {
|
2015-11-14 17:36:21 +03:00
|
|
|
cmd := NewGeoLocationCmd(query, "GEORADIUSBYMEMBER", key, member)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2015-10-15 00:39:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandable) 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 *commandable) 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
|
|
|
|
}
|