redis/commands.go

1034 lines
23 KiB
Go
Raw Normal View History

2012-07-25 17:00:50 +04:00
package redis
import (
"strconv"
)
2012-08-17 22:36:48 +04:00
func formatFloat(f float64) string {
return strconv.FormatFloat(f, 'f', -1, 32)
2012-07-27 18:21:50 +04:00
}
//------------------------------------------------------------------------------
2012-07-26 19:16:17 +04:00
func (c *Client) Auth(password string) *StatusReq {
req := NewStatusReq("AUTH", password)
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
func (c *Client) Echo(message string) *StringReq {
req := NewStringReq("ECHO", message)
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
func (c *Client) Ping() *StatusReq {
req := NewStatusReq("PING")
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) Select(index int64) *StatusReq {
req := NewStatusReq("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
}
//------------------------------------------------------------------------------
func (c *Client) Del(keys ...string) *IntReq {
args := append([]string{"DEL"}, keys...)
req := NewIntReq(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
func (c *Client) Dump(key string) *StringReq {
req := NewStringReq("DUMP", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) Exists(key string) *BoolReq {
req := NewBoolReq("EXISTS", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) Expire(key string, seconds int64) *BoolReq {
req := NewBoolReq("EXPIRE", key, strconv.FormatInt(seconds, 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) ExpireAt(key string, timestamp int64) *BoolReq {
req := NewBoolReq("EXPIREAT", key, strconv.FormatInt(timestamp, 10))
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
func (c *Client) Keys(pattern string) *StringSliceReq {
req := NewStringSliceReq("KEYS", pattern)
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
func (c *Client) Migrate(host, port, key string, db, timeout int64) *StatusReq {
2012-07-26 19:16:17 +04:00
req := NewStatusReq(
"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),
)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) Move(key string, db int64) *BoolReq {
req := NewBoolReq("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
}
func (c *Client) ObjectRefCount(keys ...string) *IntReq {
args := append([]string{"OBJECT", "REFCOUNT"}, keys...)
req := NewIntReq(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
func (c *Client) ObjectEncoding(keys ...string) *StringReq {
2012-07-26 19:16:17 +04:00
args := append([]string{"OBJECT", "ENCODING"}, keys...)
2012-08-17 22:36:48 +04:00
req := NewStringReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) ObjectIdleTime(keys ...string) *IntReq {
args := append([]string{"OBJECT", "IDLETIME"}, keys...)
req := NewIntReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) Persist(key string) *BoolReq {
req := NewBoolReq("PERSIST", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2012-08-05 16:09:43 +04:00
func (c *Client) PExpire(key string, milliseconds int64) *BoolReq {
2012-07-26 19:16:17 +04:00
req := NewBoolReq("PEXPIRE", key, strconv.FormatInt(milliseconds, 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
2012-08-05 16:09:43 +04:00
func (c *Client) PExpireAt(key string, milliseconds int64) *BoolReq {
2012-07-26 19:16:17 +04:00
req := NewBoolReq("PEXPIREAT", key, strconv.FormatInt(milliseconds, 10))
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) PTTL(key string) *IntReq {
req := NewIntReq("PTTL", key)
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
func (c *Client) RandomKey() *StringReq {
req := NewStringReq("RANDOMKEY")
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) Rename(key, newkey string) *StatusReq {
req := NewStatusReq("RENAME", key, newkey)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) RenameNX(key, newkey string) *BoolReq {
req := NewBoolReq("RENAMENX", key, newkey)
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
func (c *Client) Restore(key string, ttl int64, value string) *StatusReq {
2012-07-26 19:16:17 +04:00
req := NewStatusReq(
"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
}
func (c *Client) Sort(key string, sort Sort) *StringSliceReq {
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)
}
req := NewStringSliceReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) TTL(key string) *IntReq {
req := NewIntReq("TTL", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) Type(key string) *StatusReq {
req := NewStatusReq("TYPE", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
//------------------------------------------------------------------------------
func (c *Client) Append(key, value string) *IntReq {
req := NewIntReq("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
}
func (c *Client) BitCount(key string, bitCount *BitCount) *IntReq {
args := []string{"BITCOUNT", key}
if bitCount != nil {
args = append(
args,
strconv.FormatInt(bitCount.Start, 10),
strconv.FormatInt(bitCount.End, 10),
)
}
req := NewIntReq(args...)
c.Process(req)
return req
}
func (c *Client) bitOp(op, destKey string, keys ...string) *IntReq {
args := []string{"BITOP", op, destKey}
args = append(args, keys...)
req := NewIntReq(args...)
c.Process(req)
return req
}
2012-07-26 19:16:17 +04:00
2012-08-19 16:57:58 +04:00
func (c *Client) BitOpAnd(destKey string, keys ...string) *IntReq {
return c.bitOp("AND", destKey, keys...)
}
func (c *Client) BitOpOr(destKey string, keys ...string) *IntReq {
return c.bitOp("OR", destKey, keys...)
}
func (c *Client) BitOpXor(destKey string, keys ...string) *IntReq {
return c.bitOp("XOR", destKey, keys...)
}
func (c *Client) BitOpNot(destKey string, key string) *IntReq {
return c.bitOp("NOT", destKey, key)
}
2012-07-26 19:16:17 +04:00
func (c *Client) Decr(key string) *IntReq {
req := NewIntReq("DECR", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) DecrBy(key string, decrement int64) *IntReq {
req := NewIntReq("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
}
2012-08-17 22:36:48 +04:00
func (c *Client) Get(key string) *StringReq {
req := NewStringReq("GET", 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
func (c *Client) GetBit(key string, offset int64) *IntReq {
req := NewIntReq("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
}
2012-08-17 22:36:48 +04:00
func (c *Client) GetRange(key string, start, end int64) *StringReq {
req := NewStringReq(
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
}
2012-08-17 22:36:48 +04:00
func (c *Client) GetSet(key, value string) *StringReq {
req := NewStringReq("GETSET", key, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) Incr(key string) *IntReq {
req := NewIntReq("INCR", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) IncrBy(key string, value int64) *IntReq {
req := NewIntReq("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
}
2012-08-19 16:57:58 +04:00
func (c *Client) IncrByFloat(key string, value float64) *FloatReq {
req := NewFloatReq("INCRBYFLOAT", key, formatFloat(value))
c.Process(req)
return req
}
2012-07-26 19:16:17 +04:00
2012-08-17 22:36:48 +04:00
func (c *Client) MGet(keys ...string) *IfaceSliceReq {
2012-07-26 19:16:17 +04:00
args := append([]string{"MGET"}, keys...)
2012-08-17 22:36:48 +04:00
req := NewIfaceSliceReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) MSet(pairs ...string) *StatusReq {
args := append([]string{"MSET"}, pairs...)
req := NewStatusReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) MSetNX(pairs ...string) *BoolReq {
args := append([]string{"MSETNX"}, pairs...)
req := NewBoolReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) PSetEx(key string, milliseconds int64, value string) *StatusReq {
req := NewStatusReq(
"PSETEX",
key,
strconv.FormatInt(milliseconds, 10),
value,
)
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
func (c *Client) Set(key, value string) *StatusReq {
req := NewStatusReq("SET", key, value)
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
func (c *Client) SetBit(key string, offset int64, value int) *IntReq {
req := NewIntReq(
"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
}
func (c *Client) SetEx(key string, seconds int64, value string) *StatusReq {
req := NewStatusReq("SETEX", key, strconv.FormatInt(seconds, 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-06 16:09:48 +04:00
func (c *Client) SetNX(key, value string) *BoolReq {
2012-07-26 19:16:17 +04:00
req := NewBoolReq("SETNX", key, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) SetRange(key string, offset int64, value string) *IntReq {
req := NewIntReq("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
}
func (c *Client) StrLen(key string) *IntReq {
req := NewIntReq("STRLEN", 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
func (c *Client) HDel(key string, fields ...string) *IntReq {
args := append([]string{"HDEL", key}, fields...)
2012-07-25 17:00:50 +04:00
req := NewIntReq(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
func (c *Client) HExists(key, field string) *BoolReq {
req := NewBoolReq("HEXISTS", key, field)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) HGet(key, field string) *StringReq {
req := NewStringReq("HGET", key, field)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) HGetAll(key string) *StringSliceReq {
req := NewStringSliceReq("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
2012-07-26 19:16:17 +04:00
func (c *Client) HIncrBy(key, field string, incr int64) *IntReq {
req := NewIntReq("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
}
2012-08-17 22:36:48 +04:00
func (c *Client) HIncrByFloat(key, field string, incr float64) *FloatReq {
req := NewFloatReq("HINCRBYFLOAT", key, field, formatFloat(incr))
c.Process(req)
return req
}
2012-07-25 17:00:50 +04:00
2012-08-17 22:36:48 +04:00
func (c *Client) HKeys(key string) *StringSliceReq {
req := NewStringSliceReq("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
}
2012-07-26 19:16:17 +04:00
func (c *Client) HLen(key string) *IntReq {
req := NewIntReq("HLEN", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) HMGet(key string, fields ...string) *IfaceSliceReq {
2012-07-26 19:16:17 +04:00
args := append([]string{"HMGET", key}, fields...)
2012-08-17 22:36:48 +04:00
req := NewIfaceSliceReq(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
2012-07-26 19:16:17 +04:00
func (c *Client) HMSet(key, field, value string, pairs ...string) *StatusReq {
args := append([]string{"HMSET", key, field, value}, pairs...)
req := NewStatusReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) HSet(key, field, value string) *BoolReq {
2012-07-25 17:00:50 +04:00
req := NewBoolReq("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
}
2012-07-26 19:16:17 +04:00
func (c *Client) HSetNX(key, field, value string) *BoolReq {
2012-07-25 17:00:50 +04:00
req := NewBoolReq("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
}
2012-08-17 22:36:48 +04:00
func (c *Client) HVals(key string) *StringSliceReq {
req := NewStringSliceReq("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
//------------------------------------------------------------------------------
2012-08-17 22:36:48 +04:00
func (c *Client) BLPop(timeout int64, keys ...string) *StringSliceReq {
2012-07-26 19:16:17 +04:00
args := append([]string{"BLPOP"}, keys...)
args = append(args, strconv.FormatInt(timeout, 10))
2012-08-17 22:36:48 +04:00
req := NewStringSliceReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) BRPop(timeout int64, keys ...string) *StringSliceReq {
2012-07-26 19:16:17 +04:00
args := append([]string{"BRPOP"}, keys...)
args = append(args, strconv.FormatInt(timeout, 10))
2012-08-17 22:36:48 +04:00
req := NewStringSliceReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) BRPopLPush(source, destination string, timeout int64) *StringReq {
req := NewStringReq(
2012-07-26 19:16:17 +04:00
"BRPOPLPUSH",
source,
destination,
strconv.FormatInt(timeout, 10),
)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) LIndex(key string, index int64) *StringReq {
req := NewStringReq("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
}
func (c *Client) LInsert(key, op, pivot, value string) *IntReq {
req := NewIntReq("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
}
func (c *Client) LLen(key string) *IntReq {
req := NewIntReq("LLEN", key)
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
func (c *Client) LPop(key string) *StringReq {
req := NewStringReq("LPOP", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) LPush(key string, values ...string) *IntReq {
args := append([]string{"LPUSH", key}, values...)
2012-07-25 17:00:50 +04:00
req := NewIntReq(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
func (c *Client) LPushX(key, value string) *IntReq {
req := NewIntReq("LPUSHX", key, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-25 17:00:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) LRange(key string, start, stop int64) *StringSliceReq {
req := NewStringSliceReq(
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
}
2012-07-26 19:16:17 +04:00
func (c *Client) LRem(key string, count int64, value string) *IntReq {
req := NewIntReq("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
}
2012-07-26 19:16:17 +04:00
func (c *Client) LSet(key string, index int64, value string) *StatusReq {
req := NewStatusReq("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
}
2012-07-26 19:16:17 +04:00
func (c *Client) LTrim(key string, start, stop int64) *StatusReq {
req := NewStatusReq(
"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
}
2012-08-17 22:36:48 +04:00
func (c *Client) RPop(key string) *StringReq {
req := NewStringReq("RPOP", key)
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
func (c *Client) RPopLPush(source, destination string) *StringReq {
req := NewStringReq("RPOPLPUSH", source, destination)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) RPush(key string, values ...string) *IntReq {
args := append([]string{"RPUSH", key}, values...)
req := NewIntReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) RPushX(key string, value string) *IntReq {
req := NewIntReq("RPUSHX", key, value)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
//------------------------------------------------------------------------------
func (c *Client) SAdd(key string, members ...string) *IntReq {
args := append([]string{"SADD", key}, members...)
req := NewIntReq(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
func (c *Client) SCard(key string) *IntReq {
req := NewIntReq("SCARD", key)
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
func (c *Client) SDiff(keys ...string) *StringSliceReq {
2012-07-26 19:16:17 +04:00
args := append([]string{"SDIFF"}, keys...)
2012-08-17 22:36:48 +04:00
req := NewStringSliceReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) SDiffStore(destination string, keys ...string) *IntReq {
args := append([]string{"SDIFFSTORE", destination}, keys...)
req := NewIntReq(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
func (c *Client) SInter(keys ...string) *StringSliceReq {
2012-07-26 19:16:17 +04:00
args := append([]string{"SINTER"}, keys...)
2012-08-17 22:36:48 +04:00
req := NewStringSliceReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) SInterStore(destination string, keys ...string) *IntReq {
args := append([]string{"SINTERSTORE", destination}, keys...)
req := NewIntReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) SIsMember(key, member string) *BoolReq {
req := NewBoolReq("SISMEMBER", key, member)
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
func (c *Client) SMembers(key string) *StringSliceReq {
req := NewStringSliceReq("SMEMBERS", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) SMove(source, destination, member string) *BoolReq {
req := NewBoolReq("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
}
2012-08-17 22:36:48 +04:00
func (c *Client) SPop(key string) *StringReq {
req := NewStringReq("SPOP", key)
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
func (c *Client) SRandMember(key string) *StringReq {
req := NewStringReq("SRANDMEMBER", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) SRem(key string, members ...string) *IntReq {
args := append([]string{"SREM", key}, members...)
req := NewIntReq(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
func (c *Client) SUnion(keys ...string) *StringSliceReq {
2012-07-26 19:16:17 +04:00
args := append([]string{"SUNION"}, keys...)
2012-08-17 22:36:48 +04:00
req := NewStringSliceReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-26 19:16:17 +04:00
return req
}
func (c *Client) SUnionStore(destination string, keys ...string) *IntReq {
args := append([]string{"SUNIONSTORE", destination}, keys...)
req := NewIntReq(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
}
2012-08-17 22:36:48 +04:00
func (m *Z) ScoreString() string {
return formatFloat(m.Score)
2012-07-27 18:21:50 +04:00
}
2012-08-17 22:36:48 +04:00
func (c *Client) ZAdd(key string, members ...Z) *IntReq {
2012-07-27 18:21:50 +04:00
args := []string{"ZADD", key}
for _, m := range members {
args = append(args, m.ScoreString(), m.Member)
}
req := NewIntReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
func (c *Client) ZCard(key string) *IntReq {
req := NewIntReq("ZCARD", key)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
func (c *Client) ZCount(key, min, max string) *IntReq {
req := NewIntReq("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
}
2012-08-17 22:36:48 +04:00
func (c *Client) ZIncrBy(key string, increment float64, member string) *FloatReq {
req := NewFloatReq("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,
numkeys int64,
2012-08-17 22:36:48 +04:00
store ZStore,
keys ...string,
2012-07-27 18:21:50 +04:00
) *IntReq {
args := []string{"ZINTERSTORE", destination, strconv.FormatInt(numkeys, 10)}
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
}
req := NewIntReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) zRange(key string, start, stop int64, withScores bool) *StringSliceReq {
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")
}
2012-08-17 22:36:48 +04:00
req := NewStringSliceReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) ZRange(key string, start, stop int64) *StringSliceReq {
return c.zRange(key, start, stop, false)
}
func (c *Client) ZRangeWithScores(key string, start, stop int64) *StringSliceReq {
return c.zRange(key, start, stop, true)
}
func (c *Client) zRangeByScore(
2012-07-27 18:21:50 +04:00
key string,
min, max string,
withScores bool,
2012-08-17 22:36:48 +04:00
offset, count int64,
) *StringSliceReq {
2012-07-27 18:21:50 +04:00
args := []string{"ZRANGEBYSCORE", key, min, max}
if withScores {
args = append(args, "WITHSCORES")
}
2012-08-17 22:36:48 +04:00
if offset != 0 || count != 0 {
2012-07-27 18:21:50 +04:00
args = append(
args,
"LIMIT",
2012-08-17 22:36:48 +04:00
strconv.FormatInt(offset, 10),
strconv.FormatInt(count, 10),
2012-07-27 18:21:50 +04:00
)
}
2012-08-17 22:36:48 +04:00
req := NewStringSliceReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) ZRangeByScore(key string, min, max string, offset, count int64) *StringSliceReq {
return c.zRangeByScore(key, min, max, false, offset, count)
}
func (c *Client) ZRangeByScoreWithScores(key string, min, max string, offset, count int64) *StringSliceReq {
return c.zRangeByScore(key, min, max, true, offset, count)
}
func (c *Client) ZRank(key, member string) *IntReq {
req := NewIntReq("ZRANK", 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) ZRem(key string, members ...string) *IntReq {
args := append([]string{"ZREM", key}, members...)
req := NewIntReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
func (c *Client) ZRemRangeByRank(key string, start, stop int64) *IntReq {
req := NewIntReq(
"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
}
func (c *Client) ZRemRangeByScore(key, min, max string) *IntReq {
req := NewIntReq("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
}
2012-08-17 22:36:48 +04:00
func (c *Client) zRevRange(key, start, stop string, withScores bool) *StringSliceReq {
2012-07-27 18:21:50 +04:00
args := []string{"ZREVRANGE", key, start, stop}
if withScores {
args = append(args, "WITHSCORES")
}
2012-08-17 22:36:48 +04:00
req := NewStringSliceReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) ZRevRange(key, start, stop string) *StringSliceReq {
return c.zRevRange(key, start, stop, false)
}
func (c *Client) ZRevRangeWithScores(key, start, stop string) *StringSliceReq {
return c.zRevRange(key, start, stop, true)
}
func (c *Client) zRevRangeByScore(key, start, stop string, withScores bool, offset, count int64) *StringSliceReq {
2012-07-27 18:21:50 +04:00
args := []string{"ZREVRANGEBYSCORE", key, start, stop}
if withScores {
args = append(args, "WITHSCORES")
}
2012-08-17 22:36:48 +04:00
if offset != 0 || count != 0 {
2012-07-27 18:21:50 +04:00
args = append(
args,
"LIMIT",
2012-08-17 22:36:48 +04:00
strconv.FormatInt(offset, 10),
strconv.FormatInt(count, 10),
2012-07-27 18:21:50 +04:00
)
}
2012-08-17 22:36:48 +04:00
req := NewStringSliceReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) ZRevRangeByScore(key, start, stop string, offset, count int64) *StringSliceReq {
return c.zRevRangeByScore(key, start, stop, false, offset, count)
}
func (c *Client) ZRevRangeByScoreWithScores(key, start, stop string, offset, count int64) *StringSliceReq {
return c.zRevRangeByScore(key, start, stop, false, offset, count)
}
func (c *Client) ZRevRank(key, member string) *IntReq {
req := NewIntReq("ZREVRANK", 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) ZScore(key, member string) *FloatReq {
req := NewFloatReq("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,
numkeys int64,
2012-08-17 22:36:48 +04:00
store ZStore,
keys ...string,
2012-07-27 18:21:50 +04:00
) *IntReq {
args := []string{"ZUNIONSTORE", destination, strconv.FormatInt(numkeys, 10)}
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
}
req := NewIntReq(args...)
2012-08-05 16:09:43 +04:00
c.Process(req)
2012-07-27 18:21:50 +04:00
return req
}
//------------------------------------------------------------------------------
func (c *Client) BgRewriteAOF() *StatusReq {
req := NewStatusReq("BGREWRITEAOF")
c.Process(req)
return req
}
func (c *Client) BgSave() *StatusReq {
req := NewStatusReq("BGSAVE")
c.Process(req)
return req
}
func (c *Client) ClientKill(ipPort string) *StatusReq {
req := NewStatusReq("CLIENT", "KILL", ipPort)
c.Process(req)
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) ClientList() *StringReq {
req := NewStringReq("CLIENT", "LIST")
c.Process(req)
return req
}
func (c *Client) ConfigGet(parameter string) *IfaceSliceReq {
req := NewIfaceSliceReq("CONFIG", "GET", parameter)
c.Process(req)
return req
}
func (c *Client) ConfigResetStat() *StatusReq {
req := NewStatusReq("CONFIG", "RESETSTAT")
c.Process(req)
return req
}
func (c *Client) ConfigSet(parameter, value string) *StatusReq {
req := NewStatusReq("CONFIG", "SET", parameter, value)
c.Process(req)
return req
}
func (c *Client) DbSize() *IntReq {
req := NewIntReq("DBSIZE")
c.Process(req)
return req
}
func (c *Client) FlushAll() *StatusReq {
req := NewStatusReq("FLUSHALL")
c.Process(req)
return req
}
func (c *Client) FlushDb() *StatusReq {
req := NewStatusReq("FLUSHDB")
c.Process(req)
return req
}
2012-08-17 22:36:48 +04:00
func (c *Client) Info() *StringReq {
req := NewStringReq("INFO")
c.Process(req)
return req
}
func (c *Client) LastSave() *IntReq {
req := NewIntReq("LASTSAVE")
c.Process(req)
return req
}
func (c *Client) Monitor() {
panic("not implemented")
}
func (c *Client) Save() *StatusReq {
req := NewStatusReq("SAVE")
c.Process(req)
return req
}
func (c *Client) Shutdown() {
panic("not implemented")
}
func (c *Client) SlaveOf(host, port string) *StatusReq {
req := NewStatusReq("SLAVEOF", host, port)
c.Process(req)
return req
}
func (c *Client) SlowLog() {
panic("not implemented")
}
func (c *Client) Sync() {
panic("not implemented")
}
2012-08-17 22:36:48 +04:00
func (c *Client) Time() *StringSliceReq {
req := NewStringSliceReq("TIME")
c.Process(req)
return req
}