2012-07-25 17:00:50 +04:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
2014-05-11 11:42:40 +04:00
|
|
|
"time"
|
2012-07-25 17:00:50 +04:00
|
|
|
)
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func formatFloat(f float64) string {
|
2013-03-05 13:27:22 +04:00
|
|
|
return strconv.FormatFloat(f, 'f', -1, 64)
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func readTimeout(sec int64) time.Duration {
|
|
|
|
if sec == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return time.Duration(sec+1) * time.Second
|
|
|
|
}
|
|
|
|
|
2012-07-27 18:21:50 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Auth(password string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("AUTH", password)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Echo(message string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("ECHO", message)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Ping() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("PING")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Quit() *StatusCmd {
|
2012-08-25 16:40:49 +04:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Select(index int64) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("SELECT", strconv.FormatInt(index, 10))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Del(keys ...string) *IntCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"DEL"}, keys...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Expire(key string, dur time.Duration) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("EXPIRE", key, strconv.FormatInt(int64(dur/time.Second), 10))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ExpireAt(key string, tm time.Time) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("EXPIREAT", key, strconv.FormatInt(tm.Unix(), 10))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Migrate(host, port, key string, db, timeout int64) *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,
|
2012-08-17 22:36:48 +04:00
|
|
|
strconv.FormatInt(db, 10),
|
2012-07-26 19:16:17 +04:00
|
|
|
strconv.FormatInt(timeout, 10),
|
|
|
|
)
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Move(key string, db int64) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("MOVE", key, strconv.FormatInt(db, 10))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ObjectRefCount(keys ...string) *IntCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"OBJECT", "REFCOUNT"}, keys...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ObjectEncoding(keys ...string) *StringCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"OBJECT", "ENCODING"}, keys...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ObjectIdleTime(keys ...string) *DurationCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"OBJECT", "IDLETIME"}, keys...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewDurationCmd(time.Second, args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) PExpire(key string, dur time.Duration) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("PEXPIRE", key, strconv.FormatInt(int64(dur/time.Millisecond), 10))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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,
|
|
|
|
strconv.FormatInt(tm.UnixNano()/int64(time.Millisecond), 10),
|
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Restore(key string, ttl int64, 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,
|
2012-07-26 19:16:17 +04:00
|
|
|
strconv.FormatInt(ttl, 10),
|
|
|
|
value,
|
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
type Sort struct {
|
|
|
|
By string
|
|
|
|
Offset, Count float64
|
|
|
|
Get []string
|
|
|
|
Order string
|
|
|
|
IsAlpha bool
|
|
|
|
Store string
|
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Sort(key string, sort Sort) *StringSliceCmd {
|
2012-08-17 22:36:48 +04:00
|
|
|
args := []string{"SORT", key}
|
|
|
|
if sort.By != "" {
|
|
|
|
args = append(args, sort.By)
|
|
|
|
}
|
|
|
|
if sort.Offset != 0 || sort.Count != 0 {
|
|
|
|
args = append(args, "LIMIT", formatFloat(sort.Offset), formatFloat(sort.Count))
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) Scan(cursor int64, match string, count int64) *ScanCmd {
|
|
|
|
args := []string{"SCAN", strconv.FormatInt(cursor, 10)}
|
|
|
|
if match != "" {
|
|
|
|
args = append(args, "MATCH", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
|
|
|
args = append(args, "COUNT", strconv.FormatInt(count, 10))
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewScanCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) SScan(key string, cursor int64, match string, count int64) *ScanCmd {
|
|
|
|
args := []string{"SSCAN", key, strconv.FormatInt(cursor, 10)}
|
|
|
|
if match != "" {
|
|
|
|
args = append(args, "MATCH", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
|
|
|
args = append(args, "COUNT", strconv.FormatInt(count, 10))
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewScanCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) HScan(key string, cursor int64, match string, count int64) *ScanCmd {
|
|
|
|
args := []string{"HSCAN", key, strconv.FormatInt(cursor, 10)}
|
|
|
|
if match != "" {
|
|
|
|
args = append(args, "MATCH", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
|
|
|
args = append(args, "COUNT", strconv.FormatInt(count, 10))
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewScanCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ZScan(key string, cursor int64, match string, count int64) *ScanCmd {
|
|
|
|
args := []string{"ZSCAN", key, strconv.FormatInt(cursor, 10)}
|
|
|
|
if match != "" {
|
|
|
|
args = append(args, "MATCH", match)
|
|
|
|
}
|
|
|
|
if count > 0 {
|
|
|
|
args = append(args, "COUNT", strconv.FormatInt(count, 10))
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewScanCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) BitCount(key string, bitCount *BitCount) *IntCmd {
|
2012-08-19 16:57:58 +04:00
|
|
|
args := []string{"BITCOUNT", key}
|
|
|
|
if bitCount != nil {
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
strconv.FormatInt(bitCount.Start, 10),
|
|
|
|
strconv.FormatInt(bitCount.End, 10),
|
|
|
|
)
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-19 16:57:58 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) bitOp(op, destKey string, keys ...string) *IntCmd {
|
2012-08-19 16:57:58 +04:00
|
|
|
args := []string{"BITOP", op, destKey}
|
|
|
|
args = append(args, keys...)
|
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
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) BitOpAnd(destKey string, keys ...string) *IntCmd {
|
2012-08-19 16:57:58 +04:00
|
|
|
return c.bitOp("AND", destKey, keys...)
|
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) BitOpOr(destKey string, keys ...string) *IntCmd {
|
2012-08-19 16:57:58 +04:00
|
|
|
return c.bitOp("OR", destKey, keys...)
|
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) BitOpXor(destKey string, keys ...string) *IntCmd {
|
2012-08-19 16:57:58 +04:00
|
|
|
return c.bitOp("XOR", destKey, keys...)
|
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) DecrBy(key string, decrement int64) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("DECRBY", key, strconv.FormatInt(decrement, 10))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) GetBit(key string, offset int64) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("GETBIT", key, strconv.FormatInt(offset, 10))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) GetRange(key string, start, end int64) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd(
|
2012-07-26 19:16:17 +04:00
|
|
|
"GETRANGE",
|
|
|
|
key,
|
|
|
|
strconv.FormatInt(start, 10),
|
|
|
|
strconv.FormatInt(end, 10),
|
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) GetSet(key, value string) *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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) IncrBy(key string, value int64) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("INCRBY", key, strconv.FormatInt(value, 10))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) IncrByFloat(key string, value float64) *FloatCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewFloatCmd("INCRBYFLOAT", key, formatFloat(value))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-19 16:57:58 +04:00
|
|
|
}
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) MGet(keys ...string) *SliceCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"MGET"}, keys...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewSliceCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) MSet(pairs ...string) *StatusCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"MSET"}, pairs...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) MSetNX(pairs ...string) *BoolCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"MSETNX"}, pairs...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) PSetEx(key string, dur time.Duration, value string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(
|
2012-07-26 19:16:17 +04:00
|
|
|
"PSETEX",
|
|
|
|
key,
|
2014-05-11 11:42:40 +04:00
|
|
|
strconv.FormatInt(int64(dur/time.Millisecond), 10),
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Set(key, value string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("SET", key, value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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,
|
|
|
|
strconv.FormatInt(offset, 10),
|
|
|
|
strconv.FormatInt(int64(value), 10),
|
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SetEx(key string, dur time.Duration, value string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("SETEX", key, strconv.FormatInt(int64(dur/time.Second), 10), value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SetNX(key, value string) *BoolCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolCmd("SETNX", key, value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SetRange(key string, offset int64, value string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("SETRANGE", key, strconv.FormatInt(offset, 10), value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) HDel(key string, fields ...string) *IntCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"HDEL", key}, fields...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) HIncrBy(key, field string, incr int64) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("HINCRBY", key, field, strconv.FormatInt(incr, 10))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) HIncrByFloat(key, field string, incr float64) *FloatCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewFloatCmd("HINCRBYFLOAT", key, field, formatFloat(incr))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) HMGet(key string, fields ...string) *SliceCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"HMGET", key}, fields...)
|
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
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) HMSet(key, field, value string, pairs ...string) *StatusCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"HMSET", key, field, value}, pairs...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) BLPop(timeout int64, keys ...string) *StringSliceCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"BLPOP"}, keys...)
|
|
|
|
args = append(args, strconv.FormatInt(timeout, 10))
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) BRPop(timeout int64, keys ...string) *StringSliceCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"BRPOP"}, keys...)
|
|
|
|
args = append(args, strconv.FormatInt(timeout, 10))
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) BRPopLPush(source, destination string, timeout int64) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd(
|
2012-07-26 19:16:17 +04:00
|
|
|
"BRPOPLPUSH",
|
|
|
|
source,
|
|
|
|
destination,
|
|
|
|
strconv.FormatInt(timeout, 10),
|
|
|
|
)
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) LIndex(key string, index int64) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("LINDEX", key, strconv.FormatInt(index, 10))
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) LPush(key string, values ...string) *IntCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"LPUSH", key}, values...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) LPushX(key, value string) *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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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,
|
|
|
|
strconv.FormatInt(start, 10),
|
|
|
|
strconv.FormatInt(stop, 10),
|
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) LRem(key string, count int64, value string) *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("LREM", key, strconv.FormatInt(count, 10), value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) LSet(key string, index int64, value string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("LSET", key, strconv.FormatInt(index, 10), value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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,
|
|
|
|
strconv.FormatInt(start, 10),
|
|
|
|
strconv.FormatInt(stop, 10),
|
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) RPush(key string, values ...string) *IntCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"RPUSH", key}, values...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) RPushX(key string, value string) *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
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SAdd(key string, members ...string) *IntCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"SADD", key}, members...)
|
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
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SDiff(keys ...string) *StringSliceCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"SDIFF"}, keys...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SDiffStore(destination string, keys ...string) *IntCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"SDIFFSTORE", destination}, keys...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SInter(keys ...string) *StringSliceCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"SINTER"}, keys...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SInterStore(destination string, keys ...string) *IntCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"SINTERSTORE", destination}, keys...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SIsMember(key, member string) *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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SMove(source, destination, member string) *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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SRem(key string, members ...string) *IntCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"SREM", key}, members...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SUnion(keys ...string) *StringSliceCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"SUNION"}, keys...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SUnionStore(destination string, keys ...string) *IntCmd {
|
2012-07-26 19:16:17 +04:00
|
|
|
args := append([]string{"SUNIONSTORE", destination}, keys...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
type Z struct {
|
2012-07-27 18:21:50 +04:00
|
|
|
Score float64
|
|
|
|
Member string
|
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
type ZStore struct {
|
|
|
|
Weights []int64
|
|
|
|
Aggregate string
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ZAdd(key string, members ...Z) *IntCmd {
|
2012-07-27 18:21:50 +04:00
|
|
|
args := []string{"ZADD", key}
|
|
|
|
for _, m := range members {
|
2012-08-25 17:34:35 +04:00
|
|
|
args = append(args, formatFloat(m.Score), m.Member)
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ZIncrBy(key string, increment float64, member string) *FloatCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewFloatCmd("ZINCRBY", key, formatFloat(increment), member)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ZInterStore(
|
|
|
|
destination string,
|
2012-08-17 22:36:48 +04:00
|
|
|
store ZStore,
|
|
|
|
keys ...string,
|
2014-05-11 11:42:40 +04:00
|
|
|
) *IntCmd {
|
2012-08-20 14:42:33 +04:00
|
|
|
args := []string{"ZINTERSTORE", destination, strconv.FormatInt(int64(len(keys)), 10)}
|
2012-07-27 18:21:50 +04:00
|
|
|
args = append(args, keys...)
|
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 {
|
|
|
|
args = append(args, strconv.FormatInt(weight, 10))
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) zRange(key string, start, stop int64, withScores bool) *StringSliceCmd {
|
2012-07-27 18:21:50 +04:00
|
|
|
args := []string{
|
|
|
|
"ZRANGE",
|
|
|
|
key,
|
|
|
|
strconv.FormatInt(start, 10),
|
|
|
|
strconv.FormatInt(stop, 10),
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ZRange(key string, start, stop int64) *StringSliceCmd {
|
2012-08-17 22:36:48 +04:00
|
|
|
return c.zRange(key, start, stop, false)
|
|
|
|
}
|
|
|
|
|
2014-07-05 14:46:27 +04:00
|
|
|
func (c *Client) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd {
|
2013-02-02 16:17:01 +04:00
|
|
|
args := []string{
|
|
|
|
"ZRANGE",
|
|
|
|
key,
|
|
|
|
strconv.FormatInt(start, 10),
|
|
|
|
strconv.FormatInt(stop, 10),
|
|
|
|
"WITHSCORES",
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
type ZRangeByScore struct {
|
|
|
|
Min, Max string
|
|
|
|
|
|
|
|
Offset, Count int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) zRangeByScore(key string, opt ZRangeByScore, withScores bool) *StringSliceCmd {
|
|
|
|
args := []string{"ZRANGEBYSCORE", 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",
|
2014-05-11 11:42:40 +04:00
|
|
|
strconv.FormatInt(opt.Offset, 10),
|
|
|
|
strconv.FormatInt(opt.Count, 10),
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ZRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd {
|
|
|
|
return c.zRangeByScore(key, opt, false)
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-05 14:46:27 +04:00
|
|
|
func (c *Client) ZRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd {
|
2014-05-11 11:42:40 +04:00
|
|
|
args := []string{"ZRANGEBYSCORE", key, opt.Min, opt.Max, "WITHSCORES"}
|
|
|
|
if opt.Offset != 0 || opt.Count != 0 {
|
2013-02-02 16:17:01 +04:00
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
"LIMIT",
|
2014-05-11 11:42:40 +04:00
|
|
|
strconv.FormatInt(opt.Offset, 10),
|
|
|
|
strconv.FormatInt(opt.Count, 10),
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ZRem(key string, members ...string) *IntCmd {
|
2012-07-27 18:21:50 +04:00
|
|
|
args := append([]string{"ZREM", key}, members...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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,
|
|
|
|
strconv.FormatInt(start, 10),
|
|
|
|
strconv.FormatInt(stop, 10),
|
|
|
|
)
|
2014-06-25 11:40:56 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) zRevRange(key, start, stop string, withScores bool) *StringSliceCmd {
|
2012-07-27 18:21:50 +04:00
|
|
|
args := []string{"ZREVRANGE", key, start, stop}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ZRevRange(key, start, stop string) *StringSliceCmd {
|
2012-08-17 22:36:48 +04:00
|
|
|
return c.zRevRange(key, start, stop, false)
|
|
|
|
}
|
|
|
|
|
2014-07-05 14:46:27 +04:00
|
|
|
func (c *Client) ZRevRangeWithScores(key, start, stop string) *ZSliceCmd {
|
2013-02-02 16:17:01 +04:00
|
|
|
args := []string{"ZREVRANGE", key, start, stop, "WITHSCORES"}
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) zRevRangeByScore(key string, opt ZRangeByScore, withScores bool) *StringSliceCmd {
|
|
|
|
args := []string{"ZREVRANGEBYSCORE", key, opt.Max, opt.Min}
|
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",
|
2014-05-11 11:42:40 +04:00
|
|
|
strconv.FormatInt(opt.Offset, 10),
|
|
|
|
strconv.FormatInt(opt.Count, 10),
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd {
|
|
|
|
return c.zRevRangeByScore(key, opt, false)
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-05 14:46:27 +04:00
|
|
|
func (c *Client) ZRevRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd {
|
2014-05-11 11:42:40 +04:00
|
|
|
args := []string{"ZREVRANGEBYSCORE", key, opt.Max, opt.Min, "WITHSCORES"}
|
|
|
|
if opt.Offset != 0 || opt.Count != 0 {
|
2013-02-02 16:17:01 +04:00
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
"LIMIT",
|
2014-05-11 11:42:40 +04:00
|
|
|
strconv.FormatInt(opt.Offset, 10),
|
|
|
|
strconv.FormatInt(opt.Count, 10),
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) 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
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ZUnionStore(
|
|
|
|
destination string,
|
2012-08-17 22:36:48 +04:00
|
|
|
store ZStore,
|
|
|
|
keys ...string,
|
2014-05-11 11:42:40 +04:00
|
|
|
) *IntCmd {
|
2012-08-20 14:42:33 +04:00
|
|
|
args := []string{"ZUNIONSTORE", destination, strconv.FormatInt(int64(len(keys)), 10)}
|
2012-07-27 18:21:50 +04:00
|
|
|
args = append(args, keys...)
|
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 {
|
|
|
|
args = append(args, strconv.FormatInt(weight, 10))
|
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
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) BgRewriteAOF() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("BGREWRITEAOF")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) BgSave() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("BGSAVE")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ClientKill(ipPort string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("CLIENT", "KILL", ipPort)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ClientList() *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("CLIENT", "LIST")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ConfigGet(parameter string) *SliceCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewSliceCmd("CONFIG", "GET", parameter)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ConfigResetStat() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("CONFIG", "RESETSTAT")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ConfigSet(parameter, value string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("CONFIG", "SET", parameter, value)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) DbSize() *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("DBSIZE")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) FlushAll() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("FLUSHALL")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) FlushDb() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("FLUSHDB")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Info() *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("INFO")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) LastSave() *IntCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewIntCmd("LASTSAVE")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Save() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("SAVE")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) shutdown(modifier string) *StatusCmd {
|
2012-08-25 16:35:39 +04:00
|
|
|
var args []string
|
|
|
|
if modifier == "" {
|
|
|
|
args = []string{"SHUTDOWN"}
|
|
|
|
} else {
|
|
|
|
args = []string{"SHUTDOWN", modifier}
|
|
|
|
}
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd(args...)
|
|
|
|
c.Process(cmd)
|
2012-08-25 16:35:39 +04:00
|
|
|
c.Close()
|
2014-06-25 11:40:56 +04:00
|
|
|
return cmd
|
2012-08-25 16:35:39 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Shutdown() *StatusCmd {
|
2012-08-25 16:35:39 +04:00
|
|
|
return c.shutdown("")
|
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ShutdownSave() *StatusCmd {
|
2012-08-25 16:35:39 +04:00
|
|
|
return c.shutdown("SAVE")
|
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ShutdownNoSave() *StatusCmd {
|
2012-08-25 16:35:39 +04:00
|
|
|
return c.shutdown("NOSAVE")
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) SlaveOf(host, port string) *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("SLAVEOF", host, port)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) SlowLog() {
|
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) Sync() {
|
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Time() *StringSliceCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringSliceCmd("TIME")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
2012-08-20 14:42:33 +04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) Eval(script string, keys []string, args []string) *Cmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmdArgs := []string{"EVAL", script, strconv.FormatInt(int64(len(keys)), 10)}
|
|
|
|
cmdArgs = append(cmdArgs, keys...)
|
|
|
|
cmdArgs = append(cmdArgs, args...)
|
|
|
|
cmd := NewCmd(cmdArgs...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) EvalSha(sha1 string, keys []string, args []string) *Cmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmdArgs := []string{"EVALSHA", sha1, strconv.FormatInt(int64(len(keys)), 10)}
|
|
|
|
cmdArgs = append(cmdArgs, keys...)
|
|
|
|
cmdArgs = append(cmdArgs, args...)
|
|
|
|
cmd := NewCmd(cmdArgs...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ScriptExists(scripts ...string) *BoolSliceCmd {
|
2012-08-20 14:42:33 +04:00
|
|
|
args := append([]string{"SCRIPT", "EXISTS"}, scripts...)
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewBoolSliceCmd(args...)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2014-05-11 11:42:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ScriptFlush() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("SCRIPT", "FLUSH")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ScriptKill() *StatusCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStatusCmd("SCRIPT", "KILL")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
func (c *Client) ScriptLoad(script string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("SCRIPT", "LOAD", script)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:42:40 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func (c *Client) DebugObject(key string) *StringCmd {
|
2014-06-25 11:40:56 +04:00
|
|
|
cmd := NewStringCmd("DEBUG", "OBJECT", key)
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
2012-08-20 14:42:33 +04:00
|
|
|
}
|
2014-10-07 14:06:41 +04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func (c *Client) PubSubChannels(pattern string) *StringSliceCmd {
|
2014-10-07 16:40:00 +04:00
|
|
|
args := []string{"PUBSUB", "CHANNELS"}
|
|
|
|
if pattern != "*" {
|
|
|
|
args = append(args, pattern)
|
|
|
|
}
|
|
|
|
cmd := NewStringSliceCmd(args...)
|
2014-10-07 14:06:41 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2014-11-06 14:13:24 +03:00
|
|
|
func (c *Client) PubSubNumSub(channels ...string) *SliceCmd {
|
2014-10-07 14:06:41 +04:00
|
|
|
args := []string{"PUBSUB", "NUMSUB"}
|
|
|
|
args = append(args, channels...)
|
2014-11-06 14:13:24 +03:00
|
|
|
cmd := NewSliceCmd(args...)
|
2014-10-07 14:06:41 +04:00
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) PubSubNumPat() *IntCmd {
|
|
|
|
cmd := NewIntCmd("PUBSUB", "NUMPAT")
|
|
|
|
c.Process(cmd)
|
|
|
|
return cmd
|
|
|
|
}
|