redis/commands.go

1227 lines
28 KiB
Go
Raw Normal View History

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 {
req := NewStatusCmd("AUTH", password)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Echo(message string) *StringCmd {
req := NewStringCmd("ECHO", message)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Ping() *StatusCmd {
req := NewStatusCmd("PING")
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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 {
req := NewStatusCmd("SELECT", strconv.FormatInt(index, 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
//------------------------------------------------------------------------------
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Dump(key string) *StringCmd {
req := NewStringCmd("DUMP", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Exists(key string) *BoolCmd {
req := NewBoolCmd("EXISTS", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Expire(key string, dur time.Duration) *BoolCmd {
req := NewBoolCmd("EXPIRE", key, strconv.FormatInt(int64(dur/time.Second), 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ExpireAt(key string, tm time.Time) *BoolCmd {
req := NewBoolCmd("EXPIREAT", key, strconv.FormatInt(tm.Unix(), 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Keys(pattern string) *StringSliceCmd {
req := NewStringSliceCmd("KEYS", pattern)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Migrate(host, port, key string, db, timeout int64) *StatusCmd {
req := 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-05-11 11:42:40 +04:00
req.setReadTimeout(readTimeout(timeout))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Move(key string, db int64) *BoolCmd {
req := NewBoolCmd("MOVE", key, strconv.FormatInt(db, 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewStringCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewDurationCmd(time.Second, args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Persist(key string) *BoolCmd {
req := NewBoolCmd("PERSIST", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) PExpire(key string, dur time.Duration) *BoolCmd {
req := NewBoolCmd("PEXPIRE", key, strconv.FormatInt(int64(dur/time.Millisecond), 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) PExpireAt(key string, tm time.Time) *BoolCmd {
req := NewBoolCmd(
"PEXPIREAT",
key,
strconv.FormatInt(tm.UnixNano()/int64(time.Millisecond), 10),
)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) PTTL(key string) *DurationCmd {
req := NewDurationCmd(time.Millisecond, "PTTL", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) RandomKey() *StringCmd {
req := NewStringCmd("RANDOMKEY")
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Rename(key, newkey string) *StatusCmd {
req := NewStatusCmd("RENAME", key, newkey)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) RenameNX(key, newkey string) *BoolCmd {
req := NewBoolCmd("RENAMENX", key, newkey)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Restore(key string, ttl int64, value string) *StatusCmd {
req := 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,
)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewStringSliceCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) TTL(key string) *DurationCmd {
req := NewDurationCmd(time.Second, "TTL", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Type(key string) *StatusCmd {
req := NewStatusCmd("TYPE", key)
c.Process(req)
return req
}
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))
}
req := NewScanCmd(args...)
c.Process(req)
return req
}
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))
}
req := NewScanCmd(args...)
c.Process(req)
return req
}
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))
}
req := NewScanCmd(args...)
c.Process(req)
return req
}
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))
}
req := NewScanCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
//------------------------------------------------------------------------------
2014-05-11 11:42:40 +04:00
func (c *Client) Append(key, value string) *IntCmd {
req := NewIntCmd("APPEND", key, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-19 16:57:58 +04:00
c.Process(req)
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-19 16:57:58 +04:00
c.Process(req)
return req
}
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 {
req := NewIntCmd("DECR", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) DecrBy(key string, decrement int64) *IntCmd {
req := NewIntCmd("DECRBY", key, strconv.FormatInt(decrement, 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Get(key string) *StringCmd {
req := NewStringCmd("GET", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) GetBit(key string, offset int64) *IntCmd {
req := NewIntCmd("GETBIT", key, strconv.FormatInt(offset, 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) GetRange(key string, start, end int64) *StringCmd {
req := NewStringCmd(
2012-07-26 19:16:17 +04:00
"GETRANGE",
key,
strconv.FormatInt(start, 10),
strconv.FormatInt(end, 10),
)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) GetSet(key, value string) *StringCmd {
req := NewStringCmd("GETSET", key, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Incr(key string) *IntCmd {
req := NewIntCmd("INCR", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) IncrBy(key string, value int64) *IntCmd {
req := NewIntCmd("INCRBY", key, strconv.FormatInt(value, 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) IncrByFloat(key string, value float64) *FloatCmd {
req := NewFloatCmd("INCRBYFLOAT", key, formatFloat(value))
2012-08-19 16:57:58 +04:00
c.Process(req)
return req
}
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-05-11 11:42:40 +04:00
req := NewSliceCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewStatusCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewBoolCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) PSetEx(key string, dur time.Duration, value string) *StatusCmd {
req := 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,
)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Set(key, value string) *StatusCmd {
req := NewStatusCmd("SET", key, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) SetBit(key string, offset int64, value int) *IntCmd {
req := NewIntCmd(
2012-07-26 19:16:17 +04:00
"SETBIT",
key,
strconv.FormatInt(offset, 10),
strconv.FormatInt(int64(value), 10),
)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) SetEx(key string, dur time.Duration, value string) *StatusCmd {
req := NewStatusCmd("SETEX", key, strconv.FormatInt(int64(dur/time.Second), 10), value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) SetNX(key, value string) *BoolCmd {
req := NewBoolCmd("SETNX", key, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) SetRange(key string, offset int64, value string) *IntCmd {
req := NewIntCmd("SETRANGE", key, strconv.FormatInt(offset, 10), value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) StrLen(key string) *IntCmd {
req := NewIntCmd("STRLEN", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
//------------------------------------------------------------------------------
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) HExists(key, field string) *BoolCmd {
req := NewBoolCmd("HEXISTS", key, field)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) HGet(key, field string) *StringCmd {
req := NewStringCmd("HGET", key, field)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) HGetAll(key string) *StringSliceCmd {
req := NewStringSliceCmd("HGETALL", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2012-07-25 17:00:50 +04:00
2014-05-11 11:42:40 +04:00
func (c *Client) HGetAllMap(key string) *StringStringMapCmd {
req := NewStringStringMapCmd("HGETALL", key)
2013-02-02 16:17:01 +04:00
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) HIncrBy(key, field string, incr int64) *IntCmd {
req := NewIntCmd("HINCRBY", key, field, strconv.FormatInt(incr, 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
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 {
req := NewFloatCmd("HINCRBYFLOAT", key, field, formatFloat(incr))
2012-08-17 22:36:48 +04:00
c.Process(req)
return req
}
2012-07-25 17:00:50 +04:00
2014-05-11 11:42:40 +04:00
func (c *Client) HKeys(key string) *StringSliceCmd {
req := NewStringSliceCmd("HKEYS", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
2012-07-25 17:00:50 +04:00
}
2014-05-11 11:42:40 +04:00
func (c *Client) HLen(key string) *IntCmd {
req := NewIntCmd("HLEN", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewSliceCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewStatusCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) HSet(key, field, value string) *BoolCmd {
req := NewBoolCmd("HSET", key, field, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) HSetNX(key, field, value string) *BoolCmd {
req := NewBoolCmd("HSETNX", key, field, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) HVals(key string) *StringSliceCmd {
req := NewStringSliceCmd("HVALS", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewStringSliceCmd(args...)
req.setReadTimeout(readTimeout(timeout))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewStringSliceCmd(args...)
req.setReadTimeout(readTimeout(timeout))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) BRPopLPush(source, destination string, timeout int64) *StringCmd {
req := NewStringCmd(
2012-07-26 19:16:17 +04:00
"BRPOPLPUSH",
source,
destination,
strconv.FormatInt(timeout, 10),
)
2014-05-11 11:42:40 +04:00
req.setReadTimeout(readTimeout(timeout))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) LIndex(key string, index int64) *StringCmd {
req := NewStringCmd("LINDEX", key, strconv.FormatInt(index, 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) LInsert(key, op, pivot, value string) *IntCmd {
req := NewIntCmd("LINSERT", key, op, pivot, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) LLen(key string) *IntCmd {
req := NewIntCmd("LLEN", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) LPop(key string) *StringCmd {
req := NewStringCmd("LPOP", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) LPushX(key, value string) *IntCmd {
req := NewIntCmd("LPUSHX", key, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) LRange(key string, start, stop int64) *StringSliceCmd {
req := NewStringSliceCmd(
2012-07-26 19:16:17 +04:00
"LRANGE",
key,
strconv.FormatInt(start, 10),
strconv.FormatInt(stop, 10),
)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) LRem(key string, count int64, value string) *IntCmd {
req := NewIntCmd("LREM", key, strconv.FormatInt(count, 10), value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) LSet(key string, index int64, value string) *StatusCmd {
req := NewStatusCmd("LSET", key, strconv.FormatInt(index, 10), value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) LTrim(key string, start, stop int64) *StatusCmd {
req := NewStatusCmd(
2012-07-26 19:16:17 +04:00
"LTRIM",
key,
strconv.FormatInt(start, 10),
strconv.FormatInt(stop, 10),
)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) RPop(key string) *StringCmd {
req := NewStringCmd("RPOP", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) RPopLPush(source, destination string) *StringCmd {
req := NewStringCmd("RPOPLPUSH", source, destination)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) RPushX(key string, value string) *IntCmd {
req := NewIntCmd("RPUSHX", key, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
//------------------------------------------------------------------------------
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2012-07-26 19:16:17 +04:00
2014-05-11 11:42:40 +04:00
func (c *Client) SCard(key string) *IntCmd {
req := NewIntCmd("SCARD", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewStringSliceCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewStringSliceCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) SIsMember(key, member string) *BoolCmd {
req := NewBoolCmd("SISMEMBER", key, member)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) SMembers(key string) *StringSliceCmd {
req := NewStringSliceCmd("SMEMBERS", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) SMove(source, destination, member string) *BoolCmd {
req := NewBoolCmd("SMOVE", source, destination, member)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) SPop(key string) *StringCmd {
req := NewStringCmd("SPOP", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) SRandMember(key string) *StringCmd {
req := NewStringCmd("SRANDMEMBER", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewStringSliceCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
//------------------------------------------------------------------------------
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZCard(key string) *IntCmd {
req := NewIntCmd("ZCARD", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZCount(key, min, max string) *IntCmd {
req := NewIntCmd("ZCOUNT", key, min, max)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZIncrBy(key string, increment float64, member string) *FloatCmd {
req := NewFloatCmd("ZINCRBY", key, formatFloat(increment), member)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewStringSliceCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
func (c *Client) ZRangeWithScores(key string, start, stop int64) *StringSliceCmd {
2012-08-17 22:36:48 +04:00
return c.zRange(key, start, stop, true)
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZRangeWithScoresMap(key string, start, stop int64) *StringFloatMapCmd {
2013-02-02 16:17:01 +04:00
args := []string{
"ZRANGE",
key,
strconv.FormatInt(start, 10),
strconv.FormatInt(stop, 10),
"WITHSCORES",
}
2014-05-11 11:42:40 +04:00
req := NewStringFloatMapCmd(args...)
2013-02-02 16:17:01 +04:00
c.Process(req)
return req
}
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-05-11 11:42:40 +04:00
req := NewStringSliceCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
func (c *Client) ZRangeByScoreWithScores(key string, opt ZRangeByScore) *StringSliceCmd {
return c.zRangeByScore(key, opt, true)
2012-08-17 22:36:48 +04:00
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZRangeByScoreWithScoresMap(key string, opt ZRangeByScore) *StringFloatMapCmd {
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-05-11 11:42:40 +04:00
req := NewStringFloatMapCmd(args...)
2013-02-02 16:17:01 +04:00
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZRank(key, member string) *IntCmd {
req := NewIntCmd("ZRANK", key, member)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZRemRangeByRank(key string, start, stop int64) *IntCmd {
req := NewIntCmd(
2012-07-27 18:21:50 +04:00
"ZREMRANGEBYRANK",
key,
strconv.FormatInt(start, 10),
strconv.FormatInt(stop, 10),
)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZRemRangeByScore(key, min, max string) *IntCmd {
req := NewIntCmd("ZREMRANGEBYSCORE", key, min, max)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewStringSliceCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
func (c *Client) ZRevRangeWithScores(key, start, stop string) *StringSliceCmd {
2012-08-17 22:36:48 +04:00
return c.zRevRange(key, start, stop, true)
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZRevRangeWithScoresMap(key, start, stop string) *StringFloatMapCmd {
2013-02-02 16:17:01 +04:00
args := []string{"ZREVRANGE", key, start, stop, "WITHSCORES"}
2014-05-11 11:42:40 +04:00
req := NewStringFloatMapCmd(args...)
2013-02-02 16:17:01 +04:00
c.Process(req)
return req
}
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-05-11 11:42:40 +04:00
req := NewStringSliceCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
func (c *Client) ZRevRangeByScoreWithScores(key string, opt ZRangeByScore) *StringSliceCmd {
return c.zRevRangeByScore(key, opt, true)
2012-08-17 22:36:48 +04:00
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZRevRangeByScoreWithScoresMap(key string, opt ZRangeByScore) *StringFloatMapCmd {
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-05-11 11:42:40 +04:00
req := NewStringFloatMapCmd(args...)
2013-02-02 16:17:01 +04:00
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZRevRank(key, member string) *IntCmd {
req := NewIntCmd("ZREVRANK", key, member)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ZScore(key, member string) *FloatCmd {
req := NewFloatCmd("ZSCORE", key, member)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
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-05-11 11:42:40 +04:00
req := NewIntCmd(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
//------------------------------------------------------------------------------
2014-05-11 11:42:40 +04:00
func (c *Client) BgRewriteAOF() *StatusCmd {
req := NewStatusCmd("BGREWRITEAOF")
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) BgSave() *StatusCmd {
req := NewStatusCmd("BGSAVE")
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ClientKill(ipPort string) *StatusCmd {
req := NewStatusCmd("CLIENT", "KILL", ipPort)
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ClientList() *StringCmd {
req := NewStringCmd("CLIENT", "LIST")
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ConfigGet(parameter string) *SliceCmd {
req := NewSliceCmd("CONFIG", "GET", parameter)
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ConfigResetStat() *StatusCmd {
req := NewStatusCmd("CONFIG", "RESETSTAT")
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ConfigSet(parameter, value string) *StatusCmd {
req := NewStatusCmd("CONFIG", "SET", parameter, value)
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) DbSize() *IntCmd {
req := NewIntCmd("DBSIZE")
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) FlushAll() *StatusCmd {
req := NewStatusCmd("FLUSHALL")
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) FlushDb() *StatusCmd {
req := NewStatusCmd("FLUSHDB")
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Info() *StringCmd {
req := NewStringCmd("INFO")
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) LastSave() *IntCmd {
req := NewIntCmd("LASTSAVE")
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) Save() *StatusCmd {
req := NewStatusCmd("SAVE")
c.Process(req)
return req
}
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-05-11 11:42:40 +04:00
req := NewStatusCmd(args...)
2012-08-25 16:35:39 +04:00
c.Process(req)
c.Close()
return req
}
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")
}
2014-05-11 11:42:40 +04:00
func (c *Client) SlaveOf(host, port string) *StatusCmd {
req := NewStatusCmd("SLAVEOF", host, port)
c.Process(req)
return req
}
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 {
req := NewStringSliceCmd("TIME")
c.Process(req)
return req
}
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 {
2012-08-20 14:42:33 +04:00
reqArgs := []string{"EVAL", script, strconv.FormatInt(int64(len(keys)), 10)}
reqArgs = append(reqArgs, keys...)
reqArgs = append(reqArgs, args...)
2014-05-11 11:42:40 +04:00
req := NewCmd(reqArgs...)
2012-08-20 14:42:33 +04:00
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) EvalSha(sha1 string, keys []string, args []string) *Cmd {
2012-08-20 14:42:33 +04:00
reqArgs := []string{"EVALSHA", sha1, strconv.FormatInt(int64(len(keys)), 10)}
reqArgs = append(reqArgs, keys...)
reqArgs = append(reqArgs, args...)
2014-05-11 11:42:40 +04:00
req := NewCmd(reqArgs...)
2012-08-20 14:42:33 +04:00
c.Process(req)
return req
}
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-05-11 11:42:40 +04:00
req := NewBoolSliceCmd(args...)
c.Process(req)
return req
}
func (c *Client) ScriptFlush() *StatusCmd {
req := NewStatusCmd("SCRIPT", "FLUSH")
2012-08-20 14:42:33 +04:00
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ScriptKill() *StatusCmd {
req := NewStatusCmd("SCRIPT", "KILL")
2012-08-20 14:42:33 +04:00
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
func (c *Client) ScriptLoad(script string) *StringCmd {
req := NewStringCmd("SCRIPT", "LOAD", script)
2012-08-20 14:42:33 +04:00
c.Process(req)
return req
}
2014-05-11 11:42:40 +04:00
//------------------------------------------------------------------------------
func (c *Client) DebugObject(key string) *StringCmd {
req := NewStringCmd("DEBUG", "OBJECT", key)
2012-08-20 14:42:33 +04:00
c.Process(req)
return req
}