2012-07-25 17:00:50 +04:00
|
|
|
package redis_test
|
|
|
|
|
|
|
|
import (
|
2012-08-12 22:41:44 +04:00
|
|
|
"bytes"
|
2012-08-20 14:42:33 +04:00
|
|
|
"fmt"
|
2012-08-25 16:35:39 +04:00
|
|
|
"io"
|
2012-08-06 12:33:49 +04:00
|
|
|
"net"
|
2012-08-13 15:45:32 +04:00
|
|
|
"runtime"
|
2012-08-17 22:36:48 +04:00
|
|
|
"sort"
|
2012-07-27 15:43:30 +04:00
|
|
|
"strconv"
|
2012-08-05 16:09:43 +04:00
|
|
|
"sync"
|
2012-07-25 17:00:50 +04:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
. "launchpad.net/gocheck"
|
|
|
|
|
2012-07-27 15:43:30 +04:00
|
|
|
"github.com/vmihailenco/redis"
|
2012-07-25 17:00:50 +04:00
|
|
|
)
|
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
const redisAddr = ":6379"
|
2012-08-09 15:51:43 +04:00
|
|
|
|
2012-07-25 17:00:50 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-25 16:35:39 +04:00
|
|
|
func sortStrings(slice []string) []string {
|
|
|
|
sort.Strings(slice)
|
|
|
|
return slice
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2012-08-25 16:35:39 +04:00
|
|
|
//------------------------------------------------------------------------------
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-25 16:35:39 +04:00
|
|
|
type RedisShutdownTest struct {
|
|
|
|
client *redis.Client
|
|
|
|
}
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-25 16:35:39 +04:00
|
|
|
var _ = Suite(&RedisShutdownTest{})
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-25 16:35:39 +04:00
|
|
|
func (t *RedisShutdownTest) SetUpTest(c *C) {
|
|
|
|
t.client = redis.NewTCPClient(redisAddr, "", -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisShutdownTest) TestShutdown(c *C) {
|
|
|
|
c.Skip("shutdowns server")
|
|
|
|
|
|
|
|
shutdown := t.client.Shutdown()
|
|
|
|
c.Check(shutdown.Err(), Equals, io.EOF)
|
|
|
|
c.Check(shutdown.Val(), Equals, "")
|
|
|
|
|
|
|
|
ping := t.client.Ping()
|
|
|
|
c.Check(ping.Err(), ErrorMatches, "dial tcp <nil>:[0-9]+: connection refused")
|
|
|
|
c.Check(ping.Val(), Equals, "")
|
2012-08-17 22:36:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-25 16:35:39 +04:00
|
|
|
type RedisTest struct {
|
|
|
|
openedConnCount, closedConnCount, initedConnCount int64
|
|
|
|
client *redis.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ = Suite(&RedisTest{})
|
|
|
|
|
|
|
|
func Test(t *testing.T) { TestingT(t) }
|
|
|
|
|
2012-07-25 17:00:50 +04:00
|
|
|
func (t *RedisTest) SetUpTest(c *C) {
|
2012-08-20 00:59:52 +04:00
|
|
|
if t.client == nil {
|
2012-08-20 15:46:41 +04:00
|
|
|
openConn := func() (net.Conn, error) {
|
2012-08-20 00:59:52 +04:00
|
|
|
t.openedConnCount++
|
|
|
|
return net.Dial("tcp", redisAddr)
|
|
|
|
}
|
|
|
|
initConn := func(c *redis.Client) error {
|
|
|
|
t.initedConnCount++
|
|
|
|
return nil
|
|
|
|
}
|
2012-08-20 15:46:41 +04:00
|
|
|
closeConn := func(conn net.Conn) error {
|
2012-08-20 00:59:52 +04:00
|
|
|
t.closedConnCount++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
t.client = redis.NewClient(openConn, closeConn, initConn)
|
|
|
|
t.client.ConnPool.(*redis.MultiConnPool).MaxCap = 10
|
2012-08-11 18:42:10 +04:00
|
|
|
}
|
2012-08-20 00:59:52 +04:00
|
|
|
|
|
|
|
t.openedConnCount = 0
|
2012-08-19 16:57:58 +04:00
|
|
|
t.closedConnCount = 0
|
|
|
|
t.initedConnCount = 0
|
2012-08-20 00:59:52 +04:00
|
|
|
t.resetRedis(c)
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TearDownTest(c *C) {
|
2012-08-20 00:59:52 +04:00
|
|
|
t.resetRedis(c)
|
|
|
|
c.Assert(t.openedConnCount, Equals, t.initedConnCount)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) resetRedis(c *C) {
|
|
|
|
c.Assert(t.client.Select(1).Err(), IsNil)
|
|
|
|
c.Assert(t.client.FlushDb().Err(), IsNil)
|
|
|
|
|
|
|
|
c.Assert(t.client.Select(0).Err(), IsNil)
|
2012-08-12 22:41:44 +04:00
|
|
|
c.Assert(t.client.FlushDb().Err(), IsNil)
|
2012-08-20 00:59:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) resetClient(c *C) {
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(t.client.Close(), IsNil)
|
2012-08-20 00:59:52 +04:00
|
|
|
t.openedConnCount = 0
|
|
|
|
t.initedConnCount = 0
|
|
|
|
t.closedConnCount = 0
|
2012-08-05 16:09:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
func (t *RedisTest) TestRunWithouthCheckingErrVal(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-12 22:41:44 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(get.Val(), Equals, "hello")
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
}
|
|
|
|
|
2012-08-12 22:41:44 +04:00
|
|
|
func (t *RedisTest) TestGetSpecChars(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", "hello1\r\nhello2\r\n")
|
2012-08-12 22:41:44 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key")
|
2012-08-12 22:41:44 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(get.Val(), Equals, "hello1\r\nhello2\r\n")
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestGetBigVal(c *C) {
|
|
|
|
val := string(bytes.Repeat([]byte{'*'}, 2<<16))
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", val)
|
2012-08-12 22:41:44 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key")
|
2012-08-12 22:41:44 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, val)
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func (t *RedisTest) TestConnPoolMaxCap(c *C) {
|
2012-08-20 00:59:52 +04:00
|
|
|
t.resetClient(c)
|
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
ping := t.client.Ping()
|
|
|
|
c.Assert(ping.Err(), IsNil)
|
|
|
|
c.Assert(ping.Val(), Equals, "PONG")
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
c.Assert(t.client.Close(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(t.openedConnCount, Equals, int64(10))
|
|
|
|
c.Assert(t.closedConnCount, Equals, int64(10))
|
2012-08-11 18:42:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestConnPoolMaxCapOnPipelineClient(c *C) {
|
2012-08-20 00:59:52 +04:00
|
|
|
t.resetClient(c)
|
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
pipeline, err := t.client.PipelineClient()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
ping := pipeline.Ping()
|
|
|
|
reqs, err := pipeline.RunQueued()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(reqs, HasLen, 1)
|
|
|
|
c.Assert(ping.Err(), IsNil)
|
|
|
|
c.Assert(ping.Val(), Equals, "PONG")
|
|
|
|
|
|
|
|
c.Assert(pipeline.Close(), IsNil)
|
|
|
|
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
c.Assert(t.client.Close(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(t.openedConnCount, Equals, int64(10))
|
|
|
|
c.Assert(t.closedConnCount, Equals, int64(10))
|
2012-08-11 18:42:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestConnPoolMaxCapOnMultiClient(c *C) {
|
2012-08-20 00:59:52 +04:00
|
|
|
t.resetClient(c)
|
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
multi, err := t.client.MultiClient()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
var ping *redis.StatusReq
|
|
|
|
reqs, err := multi.Exec(func() {
|
|
|
|
ping = multi.Ping()
|
|
|
|
})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(reqs, HasLen, 1)
|
|
|
|
c.Assert(ping.Err(), IsNil)
|
|
|
|
c.Assert(ping.Val(), Equals, "PONG")
|
|
|
|
|
|
|
|
c.Assert(multi.Close(), IsNil)
|
|
|
|
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
c.Assert(t.client.Close(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(t.openedConnCount, Equals, int64(10))
|
|
|
|
c.Assert(t.closedConnCount, Equals, int64(10))
|
2012-08-11 18:42:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestConnPoolMaxCapOnPubSubClient(c *C) {
|
2012-08-20 00:59:52 +04:00
|
|
|
t.resetClient(c)
|
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
pubsub, err := t.client.PubSubClient()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
_, err = pubsub.Subscribe()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
|
|
|
c.Assert(pubsub.Close(), IsNil)
|
|
|
|
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
c.Assert(t.client.Close(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(t.openedConnCount, Equals, int64(1000))
|
|
|
|
c.Assert(t.closedConnCount, Equals, int64(1000))
|
2012-08-11 18:42:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestConnPoolRemovesBrokenConn(c *C) {
|
|
|
|
conn, err := net.Dial("tcp", redisAddr)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(conn.Close(), IsNil)
|
|
|
|
|
|
|
|
client := redis.NewTCPClient(redisAddr, "", -1)
|
|
|
|
client.ConnPool.(*redis.MultiConnPool).MaxCap = 1
|
|
|
|
defer func() {
|
2012-08-12 22:41:44 +04:00
|
|
|
c.Assert(client.Close(), IsNil)
|
2012-08-11 18:42:10 +04:00
|
|
|
}()
|
|
|
|
|
|
|
|
c.Assert(client.ConnPool.Add(redis.NewConn(conn)), IsNil)
|
|
|
|
|
|
|
|
ping := client.Ping()
|
|
|
|
c.Assert(ping.Err().Error(), Equals, "use of closed network connection")
|
|
|
|
c.Assert(ping.Val(), Equals, "")
|
|
|
|
|
|
|
|
ping = client.Ping()
|
|
|
|
c.Assert(ping.Err(), IsNil)
|
|
|
|
c.Assert(ping.Val(), Equals, "PONG")
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2012-07-26 19:16:17 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func (t *RedisTest) TestAuth(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
auth := t.client.Auth("password")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(auth.Err(), ErrorMatches, "ERR Client sent AUTH, but no password is set")
|
|
|
|
c.Assert(auth.Val(), Equals, "")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestEcho(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
echo := t.client.Echo("hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(echo.Err(), IsNil)
|
|
|
|
c.Assert(echo.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-07-25 17:00:50 +04:00
|
|
|
func (t *RedisTest) TestPing(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
ping := t.client.Ping()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(ping.Err(), IsNil)
|
|
|
|
c.Assert(ping.Val(), Equals, "PONG")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSelect(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sel := t.client.Select(1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sel.Err(), IsNil)
|
|
|
|
c.Assert(sel.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
//------------------------------------------------------------------------------
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysDel(c *C) {
|
|
|
|
set := t.client.Set("key1", "Hello")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-17 22:36:48 +04:00
|
|
|
set = t.client.Set("key2", "World")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
del := t.client.Del("key1", "key2", "key3")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(del.Err(), IsNil)
|
|
|
|
c.Assert(del.Val(), Equals, int64(2))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysDump(c *C) {
|
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-17 22:36:48 +04:00
|
|
|
|
|
|
|
dump := t.client.Dump("key")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(dump.Err(), IsNil)
|
|
|
|
c.Assert(dump.Val(), Equals, "\x00\x05hello\x06\x00\xf5\x9f\xb7\xf6\x90a\x1c\x99")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysExists(c *C) {
|
|
|
|
set := t.client.Set("key1", "Hello")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
exists := t.client.Exists("key1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(exists.Err(), IsNil)
|
|
|
|
c.Assert(exists.Val(), Equals, true)
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
exists = t.client.Exists("key2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(exists.Err(), IsNil)
|
|
|
|
c.Assert(exists.Val(), Equals, false)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysExpire(c *C) {
|
|
|
|
set := t.client.Set("key", "Hello")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
expire := t.client.Expire("key", 10)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(expire.Err(), IsNil)
|
|
|
|
c.Assert(expire.Val(), Equals, true)
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
ttl := t.client.TTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(ttl.Err(), IsNil)
|
|
|
|
c.Assert(ttl.Val(), Equals, int64(10))
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
set = t.client.Set("key", "Hello World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
ttl = t.client.TTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(ttl.Err(), IsNil)
|
|
|
|
c.Assert(ttl.Val(), Equals, int64(-1))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysExpireAt(c *C) {
|
|
|
|
set := t.client.Set("key", "Hello")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
exists := t.client.Exists("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(exists.Err(), IsNil)
|
|
|
|
c.Assert(exists.Val(), Equals, true)
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
expireAt := t.client.ExpireAt("key", 1293840000)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(expireAt.Err(), IsNil)
|
|
|
|
c.Assert(expireAt.Val(), Equals, true)
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
exists = t.client.Exists("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(exists.Err(), IsNil)
|
|
|
|
c.Assert(exists.Val(), Equals, false)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysKeys(c *C) {
|
|
|
|
mset := t.client.MSet("one", "1", "two", "2", "three", "3", "four", "4")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(mset.Err(), IsNil)
|
|
|
|
c.Assert(mset.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
keys := t.client.Keys("*o*")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(keys.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(sortStrings(keys.Val()), DeepEquals, []string{"four", "one", "two"})
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
keys = t.client.Keys("t??")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(keys.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(keys.Val(), DeepEquals, []string{"two"})
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
keys = t.client.Keys("*")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(keys.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(
|
|
|
|
sortStrings(keys.Val()),
|
|
|
|
DeepEquals,
|
|
|
|
[]string{"four", "one", "three", "two"},
|
|
|
|
)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysMigrate(c *C) {
|
|
|
|
migrate := t.client.Migrate("localhost", "6380", "key", 0, 0)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(migrate.Err(), IsNil)
|
|
|
|
c.Assert(migrate.Val(), Equals, "NOKEY")
|
2012-08-17 22:36:48 +04:00
|
|
|
|
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-17 22:36:48 +04:00
|
|
|
|
|
|
|
migrate = t.client.Migrate("localhost", "6380", "key", 0, 0)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(migrate.Err(), ErrorMatches, "IOERR error or timeout writing to target instance")
|
|
|
|
c.Assert(migrate.Val(), Equals, "")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysMove(c *C) {
|
|
|
|
move := t.client.Move("key", 1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(move.Err(), IsNil)
|
|
|
|
c.Assert(move.Val(), Equals, false)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
move = t.client.Move("key", 1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(move.Err(), IsNil)
|
|
|
|
c.Assert(move.Val(), Equals, true)
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), Equals, redis.Nil)
|
|
|
|
c.Assert(get.Val(), Equals, "")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sel := t.client.Select(1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sel.Err(), IsNil)
|
|
|
|
c.Assert(sel.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get = t.client.Get("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(get.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysObject(c *C) {
|
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
refCount := t.client.ObjectRefCount("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(refCount.Err(), IsNil)
|
|
|
|
c.Assert(refCount.Val(), Equals, int64(1))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
enc := t.client.ObjectEncoding("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(enc.Err(), IsNil)
|
|
|
|
c.Assert(enc.Val(), Equals, "raw")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
idleTime := t.client.ObjectIdleTime("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(idleTime.Err(), IsNil)
|
|
|
|
c.Assert(idleTime.Val(), Equals, int64(0))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysPersist(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
set := t.client.Set("key", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
expire := t.client.Expire("key", 10)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(expire.Err(), IsNil)
|
|
|
|
c.Assert(expire.Val(), Equals, true)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
ttl := t.client.TTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(ttl.Err(), IsNil)
|
|
|
|
c.Assert(ttl.Val(), Equals, int64(10))
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
persist := t.client.Persist("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(persist.Err(), IsNil)
|
|
|
|
c.Assert(persist.Val(), Equals, true)
|
2012-08-06 16:09:48 +04:00
|
|
|
|
|
|
|
ttl = t.client.TTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(ttl.Err(), IsNil)
|
|
|
|
c.Assert(ttl.Val(), Equals, int64(-1))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysPExpire(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
set := t.client.Set("key", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
pexpire := t.client.PExpire("key", 1900)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(pexpire.Err(), IsNil)
|
|
|
|
c.Assert(pexpire.Val(), Equals, true)
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
ttl := t.client.TTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(ttl.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(ttl.Val(), Equals, int64(2))
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
pttl := t.client.PTTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(pttl.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(pttl.Val() > 1800 && pttl.Val() <= 1900, Equals, true)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysPExpireAt(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
set := t.client.Set("key", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
pExpireAt := t.client.PExpireAt("key", 1555555555005)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(pExpireAt.Err(), IsNil)
|
|
|
|
c.Assert(pExpireAt.Val(), Equals, true)
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
ttl := t.client.TTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(ttl.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(ttl.Val(), Not(Equals), int64(0))
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
pttl := t.client.PTTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(pttl.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(pttl.Val(), Not(Equals), int64(0))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysPTTL(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
set := t.client.Set("key", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
expire := t.client.Expire("key", 1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(expire.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-06 16:09:48 +04:00
|
|
|
|
|
|
|
pttl := t.client.PTTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(pttl.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(pttl.Val() > 900 && pttl.Val() <= 1000, Equals, true)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysRandomKey(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
randomKey := t.client.RandomKey()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(randomKey.Err(), Equals, redis.Nil)
|
|
|
|
c.Assert(randomKey.Val(), Equals, "")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
randomKey = t.client.RandomKey()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(randomKey.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(randomKey.Val(), Equals, "key")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysRename(c *C) {
|
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
status := t.client.Rename("key", "key1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(status.Err(), IsNil)
|
|
|
|
c.Assert(status.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(get.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysRenameNX(c *C) {
|
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
renameNX := t.client.RenameNX("key", "key1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(renameNX.Err(), IsNil)
|
|
|
|
c.Assert(renameNX.Val(), Equals, true)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(get.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysRestore(c *C) {
|
|
|
|
set := t.client.Set("key", "hello")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
dump := t.client.Dump("key")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(dump.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
|
|
|
|
del := t.client.Del("key")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(del.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
|
|
|
|
restore := t.client.Restore("key", 0, dump.Val())
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(restore.Err(), IsNil)
|
|
|
|
c.Assert(restore.Val(), Equals, "OK")
|
2012-08-17 22:36:48 +04:00
|
|
|
|
|
|
|
type_ := t.client.Type("key")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(type_.Err(), IsNil)
|
|
|
|
c.Assert(type_.Val(), Equals, "string")
|
2012-08-17 22:36:48 +04:00
|
|
|
|
|
|
|
lRange := t.client.Get("key")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
|
|
|
c.Assert(lRange.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysSort(c *C) {
|
|
|
|
lPush := t.client.LPush("list", "1")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(lPush.Err(), IsNil)
|
|
|
|
c.Assert(lPush.Val(), Equals, int64(1))
|
2012-08-17 22:36:48 +04:00
|
|
|
lPush = t.client.LPush("list", "3")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(lPush.Err(), IsNil)
|
|
|
|
c.Assert(lPush.Val(), Equals, int64(2))
|
2012-08-17 22:36:48 +04:00
|
|
|
lPush = t.client.LPush("list", "2")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(lPush.Err(), IsNil)
|
|
|
|
c.Assert(lPush.Val(), Equals, int64(3))
|
2012-08-17 22:36:48 +04:00
|
|
|
|
|
|
|
sort := t.client.Sort("list", redis.Sort{Offset: 0, Count: 2, Order: "ASC"})
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(sort.Err(), IsNil)
|
|
|
|
c.Assert(sort.Val(), DeepEquals, []string{"1", "2"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysTTL(c *C) {
|
|
|
|
ttl := t.client.TTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(ttl.Err(), IsNil)
|
|
|
|
c.Assert(ttl.Val(), Equals, int64(-1))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
expire := t.client.Expire("key", 60)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(expire.Err(), IsNil)
|
|
|
|
c.Assert(expire.Val(), Equals, true)
|
2012-08-06 16:09:48 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
ttl = t.client.TTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(ttl.Err(), IsNil)
|
|
|
|
c.Assert(ttl.Val(), Equals, int64(60))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdKeysType(c *C) {
|
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
type_ := t.client.Type("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(type_.Err(), IsNil)
|
|
|
|
c.Assert(type_.Val(), Equals, "string")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
//------------------------------------------------------------------------------
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsAppend(c *C) {
|
|
|
|
exists := t.client.Exists("key")
|
|
|
|
c.Assert(exists.Err(), IsNil)
|
|
|
|
c.Assert(exists.Val(), Equals, false)
|
|
|
|
|
|
|
|
append := t.client.Append("key", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(append.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(append.Val(), Equals, int64(5))
|
2012-08-19 16:57:58 +04:00
|
|
|
|
|
|
|
append = t.client.Append("key", " World")
|
|
|
|
c.Assert(append.Err(), IsNil)
|
|
|
|
c.Assert(append.Val(), Equals, int64(11))
|
|
|
|
|
|
|
|
get := t.client.Get("key")
|
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "Hello World")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestStringsBitCount(c *C) {
|
|
|
|
set := t.client.Set("key", "foobar")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
bitCount := t.client.BitCount("key", nil)
|
|
|
|
c.Assert(bitCount.Err(), IsNil)
|
|
|
|
c.Assert(bitCount.Val(), Equals, int64(26))
|
|
|
|
|
|
|
|
bitCount = t.client.BitCount("key", &redis.BitCount{0, 0})
|
|
|
|
c.Assert(bitCount.Err(), IsNil)
|
|
|
|
c.Assert(bitCount.Val(), Equals, int64(4))
|
|
|
|
|
|
|
|
bitCount = t.client.BitCount("key", &redis.BitCount{1, 1})
|
|
|
|
c.Assert(bitCount.Err(), IsNil)
|
|
|
|
c.Assert(bitCount.Val(), Equals, int64(6))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestStringsBitOpAnd(c *C) {
|
|
|
|
set := t.client.Set("key1", "1")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
set = t.client.Set("key2", "0")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
bitOpAnd := t.client.BitOpAnd("dest", "key1", "key2")
|
|
|
|
c.Assert(bitOpAnd.Err(), IsNil)
|
|
|
|
c.Assert(bitOpAnd.Val(), Equals, int64(1))
|
|
|
|
|
|
|
|
get := t.client.Get("dest")
|
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "0")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestStringsBitOpOr(c *C) {
|
|
|
|
set := t.client.Set("key1", "1")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
set = t.client.Set("key2", "0")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
bitOpOr := t.client.BitOpOr("dest", "key1", "key2")
|
|
|
|
c.Assert(bitOpOr.Err(), IsNil)
|
|
|
|
c.Assert(bitOpOr.Val(), Equals, int64(1))
|
|
|
|
|
|
|
|
get := t.client.Get("dest")
|
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "1")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestStringsBitOpXor(c *C) {
|
|
|
|
set := t.client.Set("key1", "\xff")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
set = t.client.Set("key2", "\x0f")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
bitOpXor := t.client.BitOpXor("dest", "key1", "key2")
|
|
|
|
c.Assert(bitOpXor.Err(), IsNil)
|
|
|
|
c.Assert(bitOpXor.Val(), Equals, int64(1))
|
|
|
|
|
|
|
|
get := t.client.Get("dest")
|
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "\xf0")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsBitOpNot(c *C) {
|
|
|
|
set := t.client.Set("key1", "\x00")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
bitOpNot := t.client.BitOpNot("dest", "key1")
|
|
|
|
c.Assert(bitOpNot.Err(), IsNil)
|
|
|
|
c.Assert(bitOpNot.Val(), Equals, int64(1))
|
|
|
|
|
|
|
|
get := t.client.Get("dest")
|
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "\xff")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestStringsDecr(c *C) {
|
|
|
|
set := t.client.Set("key", "10")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
decr := t.client.Decr("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(decr.Err(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(decr.Val(), Equals, int64(9))
|
|
|
|
|
|
|
|
set = t.client.Set("key", "234293482390480948029348230948")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
decr = t.client.Decr("key")
|
|
|
|
c.Assert(decr.Err(), ErrorMatches, "ERR value is not an integer or out of range")
|
|
|
|
c.Assert(decr.Val(), Equals, int64(0))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsDecrBy(c *C) {
|
|
|
|
set := t.client.Set("key", "10")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
decrBy := t.client.DecrBy("key", 5)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(decrBy.Err(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(decrBy.Val(), Equals, int64(5))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsGet(c *C) {
|
|
|
|
get := t.client.Get("_")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), Equals, redis.Nil)
|
|
|
|
c.Assert(get.Val(), Equals, "")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
set := t.client.Set("key", "hello")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
get = t.client.Get("key")
|
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "hello")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestStringsGetBit(c *C) {
|
|
|
|
setBit := t.client.SetBit("key", 7, 1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(setBit.Err(), IsNil)
|
|
|
|
c.Assert(setBit.Val(), Equals, int64(0))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
getBit := t.client.GetBit("key", 0)
|
|
|
|
c.Assert(getBit.Err(), IsNil)
|
|
|
|
c.Assert(getBit.Val(), Equals, int64(0))
|
|
|
|
|
|
|
|
getBit = t.client.GetBit("key", 7)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(getBit.Err(), IsNil)
|
|
|
|
c.Assert(getBit.Val(), Equals, int64(1))
|
2012-08-19 16:57:58 +04:00
|
|
|
|
|
|
|
getBit = t.client.GetBit("key", 100)
|
|
|
|
c.Assert(getBit.Err(), IsNil)
|
|
|
|
c.Assert(getBit.Val(), Equals, int64(0))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsGetRange(c *C) {
|
|
|
|
set := t.client.Set("key", "This is a string")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
getRange := t.client.GetRange("key", 0, 3)
|
|
|
|
c.Assert(getRange.Err(), IsNil)
|
|
|
|
c.Assert(getRange.Val(), Equals, "This")
|
|
|
|
|
|
|
|
getRange = t.client.GetRange("key", -3, -1)
|
|
|
|
c.Assert(getRange.Err(), IsNil)
|
|
|
|
c.Assert(getRange.Val(), Equals, "ing")
|
|
|
|
|
|
|
|
getRange = t.client.GetRange("key", 0, -1)
|
|
|
|
c.Assert(getRange.Err(), IsNil)
|
|
|
|
c.Assert(getRange.Val(), Equals, "This is a string")
|
|
|
|
|
|
|
|
getRange = t.client.GetRange("key", 10, 100)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(getRange.Err(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(getRange.Val(), Equals, "string")
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsGetSet(c *C) {
|
|
|
|
incr := t.client.Incr("key")
|
|
|
|
c.Assert(incr.Err(), IsNil)
|
|
|
|
c.Assert(incr.Val(), Equals, int64(1))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
getSet := t.client.GetSet("key", "0")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(getSet.Err(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(getSet.Val(), Equals, "1")
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(get.Val(), Equals, "0")
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsIncr(c *C) {
|
|
|
|
set := t.client.Set("key", "10")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
incr := t.client.Incr("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(incr.Err(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(incr.Val(), Equals, int64(11))
|
|
|
|
|
|
|
|
get := t.client.Get("key")
|
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "11")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsIncrBy(c *C) {
|
|
|
|
set := t.client.Set("key", "10")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
incrBy := t.client.IncrBy("key", 5)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(incrBy.Err(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(incrBy.Val(), Equals, int64(15))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestIncrByFloat(c *C) {
|
|
|
|
set := t.client.Set("key", "10.50")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
incrByFloat := t.client.IncrByFloat("key", 0.1)
|
|
|
|
c.Assert(incrByFloat.Err(), IsNil)
|
|
|
|
c.Assert(incrByFloat.Val(), Equals, 10.6)
|
|
|
|
|
|
|
|
set = t.client.Set("key", "5.0e3")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
incrByFloat = t.client.IncrByFloat("key", 2.0e2)
|
|
|
|
c.Assert(incrByFloat.Err(), IsNil)
|
|
|
|
c.Assert(incrByFloat.Val(), Equals, float64(5200))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsMSetMGet(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
mSet := t.client.MSet("key1", "hello1", "key2", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(mSet.Err(), IsNil)
|
|
|
|
c.Assert(mSet.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
mGet := t.client.MGet("key1", "key2", "_")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(mGet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(mGet.Val(), DeepEquals, []interface{}{"hello1", "hello2", nil})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsMSetNX(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
mSetNX := t.client.MSetNX("key1", "hello1", "key2", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(mSetNX.Err(), IsNil)
|
|
|
|
c.Assert(mSetNX.Val(), Equals, true)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
mSetNX = t.client.MSetNX("key2", "hello1", "key3", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(mSetNX.Err(), IsNil)
|
|
|
|
c.Assert(mSetNX.Val(), Equals, false)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsPSetEx(c *C) {
|
|
|
|
pSetEx := t.client.PSetEx("key", 1000, "hello")
|
|
|
|
c.Assert(pSetEx.Err(), IsNil)
|
|
|
|
c.Assert(pSetEx.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
pttl := t.client.PTTL("key")
|
|
|
|
c.Assert(pttl.Err(), IsNil)
|
|
|
|
c.Assert(pttl.Val() > 900 && pttl.Val() <= 1000, Equals, true)
|
|
|
|
|
|
|
|
get := t.client.Get("key")
|
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsSetGet(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(get.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsSetEx(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
setEx := t.client.SetEx("key", 10, "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(setEx.Err(), IsNil)
|
|
|
|
c.Assert(setEx.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
ttl := t.client.TTL("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(ttl.Err(), IsNil)
|
|
|
|
c.Assert(ttl.Val(), Equals, int64(10))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsSetNX(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
setNX := t.client.SetNX("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(setNX.Err(), IsNil)
|
|
|
|
c.Assert(setNX.Val(), Equals, true)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
setNX = t.client.SetNX("key", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(setNX.Err(), IsNil)
|
|
|
|
c.Assert(setNX.Val(), Equals, false)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(get.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsSetRange(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", "Hello World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
range_ := t.client.SetRange("key", 6, "Redis")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(range_.Err(), IsNil)
|
|
|
|
c.Assert(range_.Val(), Equals, int64(11))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "Hello Redis")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-19 16:57:58 +04:00
|
|
|
func (t *RedisTest) TestStringsStrLen(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
strLen := t.client.StrLen("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(strLen.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(strLen.Val(), Equals, int64(5))
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
strLen = t.client.StrLen("_")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(strLen.Err(), IsNil)
|
|
|
|
c.Assert(strLen.Val(), Equals, int64(0))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHDel(c *C) {
|
|
|
|
hSet := t.client.HSet("hash", "key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hDel := t.client.HDel("hash", "key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hDel.Err(), IsNil)
|
|
|
|
c.Assert(hDel.Val(), Equals, int64(1))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hDel = t.client.HDel("hash", "key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hDel.Err(), IsNil)
|
|
|
|
c.Assert(hDel.Val(), Equals, int64(0))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHExists(c *C) {
|
|
|
|
hSet := t.client.HSet("hash", "key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hExists := t.client.HExists("hash", "key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hExists.Err(), IsNil)
|
|
|
|
c.Assert(hExists.Val(), Equals, true)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hExists = t.client.HExists("hash", "key1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hExists.Err(), IsNil)
|
|
|
|
c.Assert(hExists.Val(), Equals, false)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHGet(c *C) {
|
|
|
|
hSet := t.client.HSet("hash", "key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hGet := t.client.HGet("hash", "key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hGet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(hGet.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hGet = t.client.HGet("hash", "key1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hGet.Err(), Equals, redis.Nil)
|
|
|
|
c.Assert(hGet.Val(), Equals, "")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHGetAll(c *C) {
|
|
|
|
hSet := t.client.HSet("hash", "key1", "hello1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
hSet = t.client.HSet("hash", "key2", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hGetAll := t.client.HGetAll("hash")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hGetAll.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(hGetAll.Val(), DeepEquals, []string{"key1", "hello1", "key2", "hello2"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHIncrBy(c *C) {
|
|
|
|
hSet := t.client.HSet("hash", "key", "5")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hIncrBy := t.client.HIncrBy("hash", "key", 1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hIncrBy.Err(), IsNil)
|
|
|
|
c.Assert(hIncrBy.Val(), Equals, int64(6))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hIncrBy = t.client.HIncrBy("hash", "key", -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hIncrBy.Err(), IsNil)
|
|
|
|
c.Assert(hIncrBy.Val(), Equals, int64(5))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hIncrBy = t.client.HIncrBy("hash", "key", -10)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hIncrBy.Err(), IsNil)
|
|
|
|
c.Assert(hIncrBy.Val(), Equals, int64(-5))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHIncrByFloat(c *C) {
|
|
|
|
hSet := t.client.HSet("hash", "field", "10.50")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
|
|
|
c.Assert(hSet.Val(), Equals, true)
|
2012-08-17 22:36:48 +04:00
|
|
|
|
|
|
|
hIncrByFloat := t.client.HIncrByFloat("hash", "field", 0.1)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(hIncrByFloat.Err(), IsNil)
|
|
|
|
c.Assert(hIncrByFloat.Val(), Equals, 10.6)
|
2012-08-17 22:36:48 +04:00
|
|
|
|
|
|
|
hSet = t.client.HSet("hash", "field", "5.0e3")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
|
|
|
c.Assert(hSet.Val(), Equals, false)
|
2012-08-17 22:36:48 +04:00
|
|
|
|
|
|
|
hIncrByFloat = t.client.HIncrByFloat("hash", "field", 2.0e2)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(hIncrByFloat.Err(), IsNil)
|
|
|
|
c.Assert(hIncrByFloat.Val(), Equals, float64(5200))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHKeys(c *C) {
|
|
|
|
hSet := t.client.HSet("hash", "key1", "hello1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
hSet = t.client.HSet("hash", "key2", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hKeys := t.client.HKeys("hash")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hKeys.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(hKeys.Val(), DeepEquals, []string{"key1", "key2"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHLen(c *C) {
|
|
|
|
hSet := t.client.HSet("hash", "key1", "hello1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
hSet = t.client.HSet("hash", "key2", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hLen := t.client.HLen("hash")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hLen.Err(), IsNil)
|
|
|
|
c.Assert(hLen.Val(), Equals, int64(2))
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHMGet(c *C) {
|
|
|
|
hSet := t.client.HSet("hash", "key1", "hello1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
hSet = t.client.HSet("hash", "key2", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hMGet := t.client.HMGet("hash", "key1", "key2", "_")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hMGet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(hMGet.Val(), DeepEquals, []interface{}{"hello1", "hello2", nil})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHMSet(c *C) {
|
|
|
|
hMSet := t.client.HMSet("hash", "key1", "hello1", "key2", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hMSet.Err(), IsNil)
|
|
|
|
c.Assert(hMSet.Val(), Equals, "OK")
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hGet := t.client.HGet("hash", "key1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hGet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(hGet.Val(), Equals, "hello1")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hGet = t.client.HGet("hash", "key2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hGet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(hGet.Val(), Equals, "hello2")
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHSet(c *C) {
|
|
|
|
hSet := t.client.HSet("hash", "key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
|
|
|
c.Assert(hSet.Val(), Equals, true)
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hGet := t.client.HGet("hash", "key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hGet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(hGet.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHSetNX(c *C) {
|
|
|
|
hSetNX := t.client.HSetNX("hash", "key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSetNX.Err(), IsNil)
|
|
|
|
c.Assert(hSetNX.Val(), Equals, true)
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hSetNX = t.client.HSetNX("hash", "key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSetNX.Err(), IsNil)
|
|
|
|
c.Assert(hSetNX.Val(), Equals, false)
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hGet := t.client.HGet("hash", "key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hGet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(hGet.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdHVals(c *C) {
|
|
|
|
hSet := t.client.HSet("hash", "key1", "hello1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
hSet = t.client.HSet("hash", "key2", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hSet.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
hVals := t.client.HVals("hash")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(hVals.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(hVals.Val(), DeepEquals, []string{"hello1", "hello2"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsBLPop(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list1", "a", "b", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
|
|
|
|
bLPop := t.client.BLPop(0, "list1", "list2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(bLPop.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(bLPop.Val(), DeepEquals, []string{"list1", "a"})
|
2012-08-06 16:09:48 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsBLPopBlocks(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
started := make(chan bool)
|
|
|
|
done := make(chan bool)
|
|
|
|
go func() {
|
|
|
|
started <- true
|
|
|
|
bLPop := t.client.BLPop(0, "list")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(bLPop.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(bLPop.Val(), DeepEquals, []string{"list", "a"})
|
2012-08-06 16:09:48 +04:00
|
|
|
done <- true
|
|
|
|
}()
|
|
|
|
<-started
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
c.Error("BLPop is not blocked")
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
// ok
|
|
|
|
}
|
|
|
|
|
|
|
|
rPush := t.client.RPush("list", "a")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
// ok
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
c.Error("BLPop is still blocked")
|
|
|
|
// ok
|
|
|
|
}
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsBRPop(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list1", "a", "b", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
bRPop := t.client.BRPop(0, "list1", "list2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(bRPop.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(bRPop.Val(), DeepEquals, []string{"list1", "c"})
|
2012-08-06 16:09:48 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsBRPopBlocks(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
started := make(chan bool)
|
|
|
|
done := make(chan bool)
|
|
|
|
go func() {
|
|
|
|
started <- true
|
|
|
|
bRPop := t.client.BRPop(0, "list")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(bRPop.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(bRPop.Val(), DeepEquals, []string{"list", "a"})
|
2012-08-06 16:09:48 +04:00
|
|
|
done <- true
|
|
|
|
}()
|
|
|
|
<-started
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
c.Error("BRPop is not blocked")
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
// ok
|
|
|
|
}
|
|
|
|
|
|
|
|
rPush := t.client.RPush("list", "a")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
// ok
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
c.Error("BRPop is still blocked")
|
|
|
|
// ok
|
|
|
|
}
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsBRPopLPush(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list1", "a", "b", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
bRPopLPush := t.client.BRPopLPush("list1", "list2", 0)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(bRPopLPush.Err(), IsNil)
|
|
|
|
c.Assert(bRPopLPush.Val(), Equals, "c")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsLIndex(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
lPush := t.client.LPush("list", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
lPush = t.client.LPush("list", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lIndex := t.client.LIndex("list", 0)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lIndex.Err(), IsNil)
|
|
|
|
c.Assert(lIndex.Val(), Equals, "Hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lIndex = t.client.LIndex("list", -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lIndex.Err(), IsNil)
|
|
|
|
c.Assert(lIndex.Val(), Equals, "World")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lIndex = t.client.LIndex("list", 3)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lIndex.Err(), Equals, redis.Nil)
|
|
|
|
c.Assert(lIndex.Val(), Equals, "")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsLInsert(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lInsert := t.client.LInsert("list", "BEFORE", "World", "There")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lInsert.Err(), IsNil)
|
|
|
|
c.Assert(lInsert.Val(), Equals, int64(3))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"Hello", "There", "World"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsLLen(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
lPush := t.client.LPush("list", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
lPush = t.client.LPush("list", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lLen := t.client.LLen("list")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lLen.Err(), IsNil)
|
|
|
|
c.Assert(lLen.Val(), Equals, int64(2))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsLPop(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "three")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lPop := t.client.LPop("list")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lPop.Err(), IsNil)
|
|
|
|
c.Assert(lPop.Val(), Equals, "one")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"two", "three"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsLPush(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
lPush := t.client.LPush("list", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
lPush = t.client.LPush("list", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"Hello", "World"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsLPushX(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
lPush := t.client.LPush("list", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lPushX := t.client.LPushX("list", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lPushX.Err(), IsNil)
|
|
|
|
c.Assert(lPushX.Val(), Equals, int64(2))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lPushX = t.client.LPushX("list2", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lPushX.Err(), IsNil)
|
|
|
|
c.Assert(lPushX.Val(), Equals, int64(0))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"Hello", "World"})
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange = t.client.LRange("list2", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsLRange(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "three")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, 0)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"one"})
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange = t.client.LRange("list", -3, 2)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"one", "two", "three"})
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange = t.client.LRange("list", -100, 100)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"one", "two", "three"})
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange = t.client.LRange("list", 5, 10)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsLRem(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
rPush = t.client.RPush("list", "key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRem := t.client.LRem("list", -2, "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRem.Err(), IsNil)
|
|
|
|
c.Assert(lRem.Val(), Equals, int64(2))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"hello", "key"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsLSet(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "three")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lSet := t.client.LSet("list", 0, "four")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lSet.Err(), IsNil)
|
|
|
|
c.Assert(lSet.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lSet = t.client.LSet("list", -2, "five")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lSet.Err(), IsNil)
|
|
|
|
c.Assert(lSet.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"four", "five", "three"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsLTrim(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "three")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lTrim := t.client.LTrim("list", 1, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lTrim.Err(), IsNil)
|
|
|
|
c.Assert(lTrim.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"two", "three"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsRPop(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "three")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
rPop := t.client.RPop("list")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPop.Err(), IsNil)
|
|
|
|
c.Assert(rPop.Val(), Equals, "three")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"one", "two"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsRPopLPush(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "three")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
rPopLPush := t.client.RPopLPush("list", "list2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPopLPush.Err(), IsNil)
|
|
|
|
c.Assert(rPopLPush.Val(), Equals, "three")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"one", "two"})
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange = t.client.LRange("list2", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"three"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsRPush(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
|
|
|
c.Assert(rPush.Val(), Equals, int64(1))
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush = t.client.RPush("list", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
|
|
|
c.Assert(rPush.Val(), Equals, int64(2))
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"Hello", "World"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestCmdListsRPushX(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
rPush := t.client.RPush("list", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPush.Err(), IsNil)
|
|
|
|
c.Assert(rPush.Val(), Equals, int64(1))
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
rPushX := t.client.RPushX("list", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPushX.Err(), IsNil)
|
|
|
|
c.Assert(rPushX.Val(), Equals, int64(2))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
rPushX = t.client.RPushX("list2", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(rPushX.Err(), IsNil)
|
|
|
|
c.Assert(rPushX.Val(), Equals, int64(0))
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange := t.client.LRange("list", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{"Hello", "World"})
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
lRange = t.client.LRange("list2", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(lRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(lRange.Val(), DeepEquals, []string{})
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2012-07-26 19:16:17 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSAdd(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
|
|
|
c.Assert(sAdd.Val(), Equals, int64(1))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
|
|
|
c.Assert(sAdd.Val(), Equals, int64(1))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
|
|
|
c.Assert(sAdd.Val(), Equals, int64(0))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sMembers := t.client.SMembers("set")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sMembers.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(sMembers.Val(), DeepEquals, []string{"World", "Hello"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSCard(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
|
|
|
c.Assert(sAdd.Val(), Equals, int64(1))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
|
|
|
c.Assert(sAdd.Val(), Equals, int64(1))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sCard := t.client.SCard("set")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sCard.Err(), IsNil)
|
|
|
|
c.Assert(sCard.Val(), Equals, int64(2))
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSDiff(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set1", "a")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "b")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "d")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "e")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sDiff := t.client.SDiff("set1", "set2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sDiff.Err(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(sortStrings(sDiff.Val()), DeepEquals, []string{"a", "b"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSDiffStore(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set1", "a")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "b")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "d")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "e")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sDiffStore := t.client.SDiffStore("set", "set1", "set2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sDiffStore.Err(), IsNil)
|
|
|
|
c.Assert(sDiffStore.Val(), Equals, int64(2))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sMembers := t.client.SMembers("set")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sMembers.Err(), IsNil)
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(sortStrings(sMembers.Val()), DeepEquals, []string{"a", "b"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSInter(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set1", "a")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "b")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "d")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "e")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sInter := t.client.SInter("set1", "set2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sInter.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(sInter.Val(), DeepEquals, []string{"c"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSInterStore(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set1", "a")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "b")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "d")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "e")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sInterStore := t.client.SInterStore("set", "set1", "set2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sInterStore.Err(), IsNil)
|
|
|
|
c.Assert(sInterStore.Val(), Equals, int64(1))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sMembers := t.client.SMembers("set")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sMembers.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(sMembers.Val(), DeepEquals, []string{"c"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestIsMember(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sIsMember := t.client.SIsMember("set", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sIsMember.Err(), IsNil)
|
|
|
|
c.Assert(sIsMember.Val(), Equals, true)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sIsMember = t.client.SIsMember("set", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sIsMember.Err(), IsNil)
|
|
|
|
c.Assert(sIsMember.Val(), Equals, false)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSMembers(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set", "Hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set", "World")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sMembers := t.client.SMembers("set")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sMembers.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(sMembers.Val(), DeepEquals, []string{"World", "Hello"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSMove(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set1", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "three")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sMove := t.client.SMove("set1", "set2", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sMove.Err(), IsNil)
|
|
|
|
c.Assert(sMove.Val(), Equals, true)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sMembers := t.client.SMembers("set1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sMembers.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(sMembers.Val(), DeepEquals, []string{"one"})
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sMembers = t.client.SMembers("set2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sMembers.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(sortStrings(sMembers.Val()), DeepEquals, []string{"three", "two"})
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSPop(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set", "three")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sPop := t.client.SPop("set")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sPop.Err(), IsNil)
|
|
|
|
c.Assert(sPop.Val(), Not(Equals), "")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sMembers := t.client.SMembers("set")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sMembers.Err(), IsNil)
|
|
|
|
c.Assert(sMembers.Val(), HasLen, 2)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSRandMember(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set", "three")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sRandMember := t.client.SRandMember("set")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sRandMember.Err(), IsNil)
|
|
|
|
c.Assert(sRandMember.Val(), Not(Equals), "")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sMembers := t.client.SMembers("set")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sMembers.Err(), IsNil)
|
|
|
|
c.Assert(sMembers.Val(), HasLen, 3)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSRem(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set", "three")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sRem := t.client.SRem("set", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sRem.Err(), IsNil)
|
|
|
|
c.Assert(sRem.Val(), Equals, int64(1))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sRem = t.client.SRem("set", "four")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sRem.Err(), IsNil)
|
|
|
|
c.Assert(sRem.Val(), Equals, int64(0))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sMembers := t.client.SMembers("set")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sMembers.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(
|
|
|
|
sortStrings(sMembers.Val()),
|
|
|
|
DeepEquals,
|
|
|
|
[]string{"three", "two"},
|
|
|
|
)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSUnion(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set1", "a")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "b")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "d")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "e")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sUnion := t.client.SUnion("set1", "set2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sUnion.Err(), IsNil)
|
|
|
|
c.Assert(sUnion.Val(), HasLen, 5)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSUnionStore(c *C) {
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd := t.client.SAdd("set1", "a")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "b")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set1", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "c")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "d")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
sAdd = t.client.SAdd("set2", "e")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sAdd.Err(), IsNil)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sUnionStore := t.client.SUnionStore("set", "set1", "set2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sUnionStore.Err(), IsNil)
|
|
|
|
c.Assert(sUnionStore.Val(), Equals, int64(5))
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
sMembers := t.client.SMembers("set")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(sMembers.Err(), IsNil)
|
|
|
|
c.Assert(sMembers.Val(), HasLen, 5)
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-07-27 18:21:50 +04:00
|
|
|
func (t *RedisTest) TestZAdd(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
|
|
|
c.Assert(zAdd.Val(), Equals, int64(1))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{1, "uno"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
|
|
|
c.Assert(zAdd.Val(), Equals, int64(1))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
|
|
|
c.Assert(zAdd.Val(), Equals, int64(1))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{3, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
|
|
|
c.Assert(zAdd.Val(), Equals, int64(0))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRange := t.client.ZRangeWithScores("zset", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRange.Val(), DeepEquals, []string{"one", "1", "uno", "1", "two", "3"})
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZCard(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zCard := t.client.ZCard("zset")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zCard.Err(), IsNil)
|
|
|
|
c.Assert(zCard.Val(), Equals, int64(2))
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZCount(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{3, "three"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zCount := t.client.ZCount("zset", "-inf", "+inf")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zCount.Err(), IsNil)
|
|
|
|
c.Assert(zCount.Val(), Equals, int64(3))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zCount = t.client.ZCount("zset", "(1", "3")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zCount.Err(), IsNil)
|
|
|
|
c.Assert(zCount.Val(), Equals, int64(2))
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZIncrBy(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zIncrBy := t.client.ZIncrBy("zset", 2, "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zIncrBy.Err(), IsNil)
|
|
|
|
c.Assert(zIncrBy.Val(), Equals, float64(3))
|
2012-08-06 16:09:48 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRange := t.client.ZRangeWithScores("zset", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRange.Val(), DeepEquals, []string{"two", "2", "one", "3"})
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZInterStore(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset1", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset1", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset2", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset2", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset3", redis.Z{3, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
|
|
|
|
zInterStore := t.client.ZInterStore(
|
2012-08-20 14:42:33 +04:00
|
|
|
"out", redis.ZStore{Weights: []int64{2, 3}}, "zset1", "zset2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zInterStore.Err(), IsNil)
|
|
|
|
c.Assert(zInterStore.Val(), Equals, int64(2))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRange := t.client.ZRangeWithScores("out", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRange.Val(), DeepEquals, []string{"one", "5", "two", "10"})
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZRange(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{3, "three"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRange := t.client.ZRange("zset", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRange.Val(), DeepEquals, []string{"one", "two", "three"})
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRange = t.client.ZRange("zset", 2, 3)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRange.Val(), DeepEquals, []string{"three"})
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRange = t.client.ZRange("zset", -2, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRange.Val(), DeepEquals, []string{"two", "three"})
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZRangeByScore(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{3, "three"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRangeByScore := t.client.ZRangeByScore("zset", "-inf", "+inf", 0, 0)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRangeByScore.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRangeByScore.Val(), DeepEquals, []string{"one", "two", "three"})
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRangeByScore = t.client.ZRangeByScore("zset", "1", "2", 0, 0)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRangeByScore.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRangeByScore.Val(), DeepEquals, []string{"one", "two"})
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRangeByScore = t.client.ZRangeByScore("zset", "(1", "2", 0, 0)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRangeByScore.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRangeByScore.Val(), DeepEquals, []string{"two"})
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRangeByScore = t.client.ZRangeByScore("zset", "(1", "(2", 0, 0)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRangeByScore.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRangeByScore.Val(), DeepEquals, []string{})
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZRank(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{3, "three"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zRank := t.client.ZRank("zset", "three")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRank.Err(), IsNil)
|
|
|
|
c.Assert(zRank.Val(), Equals, int64(2))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zRank = t.client.ZRank("zset", "four")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRank.Err(), Equals, redis.Nil)
|
|
|
|
c.Assert(zRank.Val(), Equals, int64(0))
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZRem(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{3, "three"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zRem := t.client.ZRem("zset", "two")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRem.Err(), IsNil)
|
|
|
|
c.Assert(zRem.Val(), Equals, int64(1))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRange := t.client.ZRangeWithScores("zset", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRange.Val(), DeepEquals, []string{"one", "1", "three", "3"})
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZRemRangeByRank(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{3, "three"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zRemRangeByRank := t.client.ZRemRangeByRank("zset", 0, 1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRemRangeByRank.Err(), IsNil)
|
|
|
|
c.Assert(zRemRangeByRank.Val(), Equals, int64(2))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRange := t.client.ZRangeWithScores("zset", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRange.Val(), DeepEquals, []string{"three", "3"})
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZRemRangeByScore(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{3, "three"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zRemRangeByScore := t.client.ZRemRangeByScore("zset", "-inf", "(2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRemRangeByScore.Err(), IsNil)
|
|
|
|
c.Assert(zRemRangeByScore.Val(), Equals, int64(1))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRange := t.client.ZRangeWithScores("zset", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRange.Val(), DeepEquals, []string{"two", "2", "three", "3"})
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZRevRange(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{3, "three"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRevRange := t.client.ZRevRange("zset", "0", "-1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRevRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRevRange.Val(), DeepEquals, []string{"three", "two", "one"})
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRevRange = t.client.ZRevRange("zset", "2", "3")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRevRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRevRange.Val(), DeepEquals, []string{"one"})
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRevRange = t.client.ZRevRange("zset", "-2", "-1")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRevRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRevRange.Val(), DeepEquals, []string{"two", "one"})
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZRevRangeByScore(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{3, "three"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRevRangeByScore := t.client.ZRevRangeByScore("zset", "+inf", "-inf", 0, 0)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRevRangeByScore.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRevRangeByScore.Val(), DeepEquals, []string{"three", "two", "one"})
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRevRangeByScore = t.client.ZRevRangeByScore("zset", "2", "(1", 0, 0)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRevRangeByScore.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRevRangeByScore.Val(), DeepEquals, []string{"two"})
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRevRangeByScore = t.client.ZRevRangeByScore("zset", "(2", "(1", 0, 0)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRevRangeByScore.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRevRangeByScore.Val(), DeepEquals, []string{})
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZRevRank(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset", redis.Z{3, "three"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zRevRank := t.client.ZRevRank("zset", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRevRank.Err(), IsNil)
|
|
|
|
c.Assert(zRevRank.Val(), Equals, int64(2))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zRevRank = t.client.ZRevRank("zset", "four")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRevRank.Err(), Equals, redis.Nil)
|
|
|
|
c.Assert(zRevRank.Val(), Equals, int64(0))
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZScore(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset", redis.Z{1.001, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
zScore := t.client.ZScore("zset", "one")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zScore.Err(), IsNil)
|
|
|
|
c.Assert(zScore.Val(), Equals, float64(1.001))
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestZUnionStore(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd := t.client.ZAdd("zset1", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset1", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset2", redis.Z{1, "one"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset2", redis.Z{2, "two"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
zAdd = t.client.ZAdd("zset2", redis.Z{3, "three"})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zAdd.Err(), IsNil)
|
2012-08-06 16:09:48 +04:00
|
|
|
|
|
|
|
zUnionStore := t.client.ZUnionStore(
|
2012-08-20 14:42:33 +04:00
|
|
|
"out", redis.ZStore{Weights: []int64{2, 3}}, "zset1", "zset2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zUnionStore.Err(), IsNil)
|
|
|
|
c.Assert(zUnionStore.Val(), Equals, int64(3))
|
2012-07-27 18:21:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
zRange := t.client.ZRangeWithScores("out", 0, -1)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(zRange.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(zRange.Val(), DeepEquals, []string{"one", "5", "three", "9", "two", "10"})
|
2012-07-27 18:21:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-09 16:27:06 +04:00
|
|
|
func (t *RedisTest) TestPatternPubSub(c *C) {
|
|
|
|
pubsub, err := t.client.PubSubClient()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(pubsub.Close(), IsNil)
|
|
|
|
}()
|
2012-08-09 16:27:06 +04:00
|
|
|
|
|
|
|
ch, err := pubsub.PSubscribe("mychannel*")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(ch, Not(IsNil))
|
2012-08-09 16:27:06 +04:00
|
|
|
|
|
|
|
pub := t.client.Publish("mychannel1", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(pub.Err(), IsNil)
|
|
|
|
c.Assert(pub.Val(), Equals, int64(1))
|
2012-08-09 16:27:06 +04:00
|
|
|
|
|
|
|
err = pubsub.PUnsubscribe("mychannel*")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
2012-08-09 16:27:06 +04:00
|
|
|
|
|
|
|
select {
|
|
|
|
case msg := <-ch:
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(msg.Err, Equals, nil)
|
|
|
|
c.Assert(msg.Name, Equals, "psubscribe")
|
|
|
|
c.Assert(msg.Channel, Equals, "mychannel*")
|
|
|
|
c.Assert(msg.Number, Equals, int64(1))
|
2012-08-09 16:27:06 +04:00
|
|
|
case <-time.After(time.Second):
|
|
|
|
c.Error("Channel is empty.")
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case msg := <-ch:
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(msg.Err, Equals, nil)
|
|
|
|
c.Assert(msg.Name, Equals, "pmessage")
|
|
|
|
c.Assert(msg.ChannelPattern, Equals, "mychannel*")
|
|
|
|
c.Assert(msg.Channel, Equals, "mychannel1")
|
|
|
|
c.Assert(msg.Message, Equals, "hello")
|
2012-08-09 16:27:06 +04:00
|
|
|
case <-time.After(time.Second):
|
|
|
|
c.Error("Channel is empty.")
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case msg := <-ch:
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(msg.Err, Equals, nil)
|
|
|
|
c.Assert(msg.Name, Equals, "punsubscribe")
|
|
|
|
c.Assert(msg.Channel, Equals, "mychannel*")
|
|
|
|
c.Assert(msg.Number, Equals, int64(0))
|
2012-08-09 16:27:06 +04:00
|
|
|
case <-time.After(time.Second):
|
|
|
|
c.Error("Channel is empty.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-25 17:00:50 +04:00
|
|
|
func (t *RedisTest) TestPubSub(c *C) {
|
2012-08-05 16:09:43 +04:00
|
|
|
pubsub, err := t.client.PubSubClient()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(pubsub.Close(), IsNil)
|
|
|
|
}()
|
2012-07-25 17:00:50 +04:00
|
|
|
|
|
|
|
ch, err := pubsub.Subscribe("mychannel")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(ch, Not(IsNil))
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-09 16:27:06 +04:00
|
|
|
ch2, err := pubsub.Subscribe("mychannel2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(ch2, Equals, ch)
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
pub := t.client.Publish("mychannel", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(pub.Err(), IsNil)
|
|
|
|
c.Assert(pub.Val(), Equals, int64(1))
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-06 16:09:48 +04:00
|
|
|
pub = t.client.Publish("mychannel2", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(pub.Err(), IsNil)
|
|
|
|
c.Assert(pub.Val(), Equals, int64(1))
|
2012-07-25 17:00:50 +04:00
|
|
|
|
|
|
|
err = pubsub.Unsubscribe("mychannel")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
2012-07-25 17:00:50 +04:00
|
|
|
|
|
|
|
err = pubsub.Unsubscribe("mychannel2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
2012-07-25 17:00:50 +04:00
|
|
|
|
|
|
|
select {
|
|
|
|
case msg := <-ch:
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(msg.Err, Equals, nil)
|
|
|
|
c.Assert(msg.Name, Equals, "subscribe")
|
|
|
|
c.Assert(msg.Channel, Equals, "mychannel")
|
|
|
|
c.Assert(msg.Number, Equals, int64(1))
|
2012-07-25 17:00:50 +04:00
|
|
|
case <-time.After(time.Second):
|
|
|
|
c.Error("Channel is empty.")
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case msg := <-ch:
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(msg.Err, Equals, nil)
|
|
|
|
c.Assert(msg.Name, Equals, "subscribe")
|
|
|
|
c.Assert(msg.Channel, Equals, "mychannel2")
|
|
|
|
c.Assert(msg.Number, Equals, int64(2))
|
2012-07-25 17:00:50 +04:00
|
|
|
case <-time.After(time.Second):
|
|
|
|
c.Error("Channel is empty.")
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case msg := <-ch:
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(msg.Err, Equals, nil)
|
|
|
|
c.Assert(msg.Name, Equals, "message")
|
|
|
|
c.Assert(msg.Channel, Equals, "mychannel")
|
|
|
|
c.Assert(msg.Message, Equals, "hello")
|
2012-07-25 17:00:50 +04:00
|
|
|
case <-time.After(time.Second):
|
|
|
|
c.Error("Channel is empty.")
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case msg := <-ch:
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(msg.Err, Equals, nil)
|
|
|
|
c.Assert(msg.Name, Equals, "message")
|
|
|
|
c.Assert(msg.Channel, Equals, "mychannel2")
|
|
|
|
c.Assert(msg.Message, Equals, "hello2")
|
2012-07-25 17:00:50 +04:00
|
|
|
case <-time.After(time.Second):
|
|
|
|
c.Error("Channel is empty.")
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case msg := <-ch:
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(msg.Err, Equals, nil)
|
|
|
|
c.Assert(msg.Name, Equals, "unsubscribe")
|
|
|
|
c.Assert(msg.Channel, Equals, "mychannel")
|
|
|
|
c.Assert(msg.Number, Equals, int64(1))
|
2012-07-25 17:00:50 +04:00
|
|
|
case <-time.After(time.Second):
|
|
|
|
c.Error("Channel is empty.")
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case msg := <-ch:
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(msg.Err, Equals, nil)
|
|
|
|
c.Assert(msg.Name, Equals, "unsubscribe")
|
|
|
|
c.Assert(msg.Channel, Equals, "mychannel2")
|
|
|
|
c.Assert(msg.Number, Equals, int64(0))
|
2012-07-25 17:00:50 +04:00
|
|
|
case <-time.After(time.Second):
|
|
|
|
c.Error("Channel is empty.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 19:16:17 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-11 19:02:28 +04:00
|
|
|
func (t *RedisTest) TestPipeline(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key2", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
pipeline, err := t.client.PipelineClient()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(pipeline.Close(), IsNil)
|
|
|
|
}()
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
set = pipeline.Set("key1", "hello1")
|
|
|
|
get := pipeline.Get("key2")
|
|
|
|
incr := pipeline.Incr("key3")
|
|
|
|
getNil := pipeline.Get("key4")
|
2012-07-29 13:42:00 +04:00
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
reqs, err := pipeline.RunQueued()
|
|
|
|
c.Assert(err, IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(reqs, HasLen, 4)
|
|
|
|
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "hello2")
|
2012-07-29 13:42:00 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(incr.Err(), IsNil)
|
|
|
|
c.Assert(incr.Val(), Equals, int64(1))
|
2012-07-29 13:42:00 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(getNil.Err(), Equals, redis.Nil)
|
|
|
|
c.Assert(getNil.Val(), Equals, "")
|
|
|
|
}
|
|
|
|
|
2012-08-20 00:19:00 +04:00
|
|
|
func (t *RedisTest) TestPipelineDiscardQueued(c *C) {
|
|
|
|
pipeline, err := t.client.PipelineClient()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(pipeline.Close(), IsNil)
|
|
|
|
}()
|
|
|
|
|
|
|
|
pipeline.Get("key")
|
|
|
|
pipeline.DiscardQueued()
|
|
|
|
reqs, err := pipeline.RunQueued()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(reqs, HasLen, 0)
|
|
|
|
}
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
func (t *RedisTest) TestPipelineFunc(c *C) {
|
|
|
|
var get *redis.StringReq
|
|
|
|
reqs, err := t.client.Pipelined(func(c *redis.PipelineClient) {
|
|
|
|
get = c.Get("foo")
|
|
|
|
})
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(reqs, HasLen, 1)
|
|
|
|
c.Assert(get.Err(), Equals, redis.Nil)
|
|
|
|
c.Assert(get.Val(), Equals, "")
|
2012-07-29 13:42:00 +04:00
|
|
|
}
|
|
|
|
|
2012-08-11 19:02:28 +04:00
|
|
|
func (t *RedisTest) TestPipelineErrValNotSet(c *C) {
|
|
|
|
pipeline, err := t.client.PipelineClient()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(pipeline.Close(), IsNil)
|
|
|
|
}()
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := pipeline.Get("key")
|
2012-08-12 22:41:44 +04:00
|
|
|
c.Assert(get.Err(), ErrorMatches, "redis: value is not set")
|
2012-08-11 19:02:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestPipelineRunQueuedOnEmptyQueue(c *C) {
|
2012-08-11 18:42:10 +04:00
|
|
|
pipeline, err := t.client.PipelineClient()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(pipeline.Close(), IsNil)
|
|
|
|
}()
|
|
|
|
|
|
|
|
reqs, err := pipeline.RunQueued()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(reqs, HasLen, 0)
|
2012-07-29 13:51:29 +04:00
|
|
|
}
|
|
|
|
|
2012-08-11 19:02:28 +04:00
|
|
|
func (t *RedisTest) TestPipelineIncrFromGoroutines(c *C) {
|
2012-08-11 18:42:10 +04:00
|
|
|
pipeline, err := t.client.PipelineClient()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(pipeline.Close(), IsNil)
|
|
|
|
}()
|
2012-08-09 18:06:26 +04:00
|
|
|
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
for i := int64(0); i < 20000; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2012-08-11 18:42:10 +04:00
|
|
|
pipeline.Incr("TestIncrPipeliningFromGoroutinesKey")
|
2012-08-09 18:06:26 +04:00
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
reqs, err := pipeline.RunQueued()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(reqs, HasLen, 20000)
|
2012-08-09 18:06:26 +04:00
|
|
|
for _, req := range reqs {
|
|
|
|
if req.Err() != nil {
|
|
|
|
c.Errorf("got %v, expected nil", req.Err())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get := t.client.Get("TestIncrPipeliningFromGoroutinesKey")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "20000")
|
2012-08-09 18:06:26 +04:00
|
|
|
}
|
|
|
|
|
2012-08-11 19:02:28 +04:00
|
|
|
func (t *RedisTest) TestPipelineEchoFromGoroutines(c *C) {
|
2012-08-11 18:42:10 +04:00
|
|
|
pipeline, err := t.client.PipelineClient()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(pipeline.Close(), IsNil)
|
|
|
|
}()
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
wg := &sync.WaitGroup{}
|
2012-08-09 18:06:26 +04:00
|
|
|
for i := int64(0); i < 1000; i += 2 {
|
2012-08-11 18:42:10 +04:00
|
|
|
wg.Add(1)
|
2012-08-09 18:06:26 +04:00
|
|
|
go func() {
|
|
|
|
msg1 := "echo" + strconv.FormatInt(i, 10)
|
|
|
|
msg2 := "echo" + strconv.FormatInt(i+1, 10)
|
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
echo1 := pipeline.Echo(msg1)
|
|
|
|
echo2 := pipeline.Echo(msg2)
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
reqs, err := pipeline.RunQueued()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(reqs, HasLen, 2)
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(echo1.Err(), IsNil)
|
|
|
|
c.Assert(echo1.Val(), Equals, msg1)
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(echo2.Err(), IsNil)
|
|
|
|
c.Assert(echo2.Val(), Equals, msg2)
|
|
|
|
|
|
|
|
wg.Done()
|
2012-08-09 18:06:26 +04:00
|
|
|
}()
|
|
|
|
}
|
2012-08-11 18:42:10 +04:00
|
|
|
wg.Wait()
|
2012-08-09 18:06:26 +04:00
|
|
|
}
|
|
|
|
|
2012-07-29 13:42:00 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
func (t *RedisTest) TestMultiExec(c *C) {
|
2012-08-09 18:06:26 +04:00
|
|
|
multi, err := t.client.MultiClient()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(multi.Close(), IsNil)
|
|
|
|
}()
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
var (
|
|
|
|
set *redis.StatusReq
|
2012-08-17 22:36:48 +04:00
|
|
|
get *redis.StringReq
|
2012-08-13 15:45:32 +04:00
|
|
|
)
|
|
|
|
reqs, err := multi.Exec(func() {
|
2012-08-17 22:36:48 +04:00
|
|
|
set = multi.Set("key", "hello")
|
|
|
|
get = multi.Get("key")
|
2012-08-13 15:45:32 +04:00
|
|
|
})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
2012-08-13 15:45:32 +04:00
|
|
|
c.Assert(reqs, HasLen, 2)
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-26 19:16:17 +04:00
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(get.Val(), Equals, "hello")
|
2012-07-26 19:16:17 +04:00
|
|
|
}
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
func (t *RedisTest) TestMultiExecDiscard(c *C) {
|
2012-08-09 18:06:26 +04:00
|
|
|
multi, err := t.client.MultiClient()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(multi.Close(), IsNil)
|
|
|
|
}()
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
reqs, err := multi.Exec(func() {
|
2012-08-17 22:36:48 +04:00
|
|
|
multi.Set("key1", "hello1")
|
2012-08-13 15:45:32 +04:00
|
|
|
multi.Discard()
|
2012-08-17 22:36:48 +04:00
|
|
|
multi.Set("key2", "hello2")
|
2012-08-13 15:45:32 +04:00
|
|
|
})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
2012-08-13 15:45:32 +04:00
|
|
|
c.Assert(reqs, HasLen, 1)
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key1")
|
2012-08-13 15:45:32 +04:00
|
|
|
c.Assert(get.Err(), Equals, redis.Nil)
|
|
|
|
c.Assert(get.Val(), Equals, "")
|
2012-07-25 17:00:50 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get = t.client.Get("key2")
|
2012-08-13 15:45:32 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(get.Val(), Equals, "hello2")
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:10 +04:00
|
|
|
func (t *RedisTest) TestMultiExecOnEmptyQueue(c *C) {
|
|
|
|
multi, err := t.client.MultiClient()
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
2012-08-12 22:41:44 +04:00
|
|
|
c.Assert(multi.Close(), IsNil)
|
2012-08-11 18:42:10 +04:00
|
|
|
}()
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
reqs, err := multi.Exec(func() {})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(reqs, HasLen, 0)
|
2012-07-29 13:51:29 +04:00
|
|
|
}
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
func (t *RedisTest) TestMultiExecIncrTransaction(c *C) {
|
2012-08-09 18:06:26 +04:00
|
|
|
multi, err := t.client.MultiClient()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(multi.Close(), IsNil)
|
|
|
|
}()
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
reqs, err := multi.Exec(func() {
|
|
|
|
for i := int64(0); i < 20000; i++ {
|
2012-08-09 18:06:26 +04:00
|
|
|
multi.Incr("TestIncrTransactionKey")
|
2012-08-13 15:45:32 +04:00
|
|
|
}
|
|
|
|
})
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(reqs, HasLen, 20000)
|
2012-08-06 16:45:38 +04:00
|
|
|
for _, req := range reqs {
|
|
|
|
if req.Err() != nil {
|
|
|
|
c.Errorf("got %v, expected nil", req.Err())
|
|
|
|
}
|
|
|
|
}
|
2012-08-05 16:09:43 +04:00
|
|
|
|
2012-08-09 18:06:26 +04:00
|
|
|
get := t.client.Get("TestIncrTransactionKey")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "20000")
|
2012-08-05 16:09:43 +04:00
|
|
|
}
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
func (t *RedisTest) transactionalIncr(c *C) ([]redis.Req, error) {
|
2012-08-09 18:06:26 +04:00
|
|
|
multi, err := t.client.MultiClient()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
defer func() {
|
|
|
|
c.Assert(multi.Close(), IsNil)
|
|
|
|
}()
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
watch := multi.Watch("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(watch.Err(), IsNil)
|
|
|
|
c.Assert(watch.Val(), Equals, "OK")
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := multi.Get("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Not(Equals), redis.Nil)
|
2012-08-09 18:06:26 +04:00
|
|
|
|
|
|
|
v, err := strconv.ParseInt(get.Val(), 10, 64)
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
2012-08-09 18:06:26 +04:00
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
reqs, err := multi.Exec(func() {
|
2012-08-17 22:36:48 +04:00
|
|
|
multi.Set("key", strconv.FormatInt(v+1, 10))
|
2012-08-13 15:45:32 +04:00
|
|
|
})
|
2012-08-09 18:06:26 +04:00
|
|
|
if err == redis.Nil {
|
2012-08-13 15:45:32 +04:00
|
|
|
return t.transactionalIncr(c)
|
2012-08-09 18:06:26 +04:00
|
|
|
}
|
2012-08-13 15:45:32 +04:00
|
|
|
return reqs, err
|
2012-08-09 18:06:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestWatchUnwatch(c *C) {
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", "0")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-08-05 16:09:43 +04:00
|
|
|
|
|
|
|
wg := &sync.WaitGroup{}
|
2012-08-09 18:06:26 +04:00
|
|
|
for i := 0; i < 1000; i++ {
|
2012-08-05 16:09:43 +04:00
|
|
|
wg.Add(1)
|
2012-08-13 15:45:32 +04:00
|
|
|
go func() {
|
|
|
|
reqs, err := t.transactionalIncr(c)
|
|
|
|
c.Assert(reqs, HasLen, 1)
|
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(reqs[0].Err(), IsNil)
|
|
|
|
wg.Done()
|
|
|
|
}()
|
2012-08-05 16:09:43 +04:00
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "1000")
|
2012-08-05 16:09:43 +04:00
|
|
|
}
|
|
|
|
|
2012-07-27 15:43:30 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
func (t *RedisTest) TestSyncEchoFromGoroutines(c *C) {
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
for i := int64(0); i < 1000; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
msg := "echo" + strconv.FormatInt(i, 10)
|
|
|
|
echo := t.client.Echo(msg)
|
|
|
|
c.Assert(echo.Err(), IsNil)
|
|
|
|
c.Assert(echo.Val(), Equals, msg)
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestIncrFromGoroutines(c *C) {
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
for i := int64(0); i < 20000; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
incr := t.client.Incr("TestIncrFromGoroutinesKey")
|
|
|
|
c.Assert(incr.Err(), IsNil)
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
get := t.client.Get("TestIncrFromGoroutinesKey")
|
|
|
|
c.Assert(get.Err(), IsNil)
|
|
|
|
c.Assert(get.Val(), Equals, "20000")
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-12 22:41:44 +04:00
|
|
|
func (t *RedisTest) TestCmdBgRewriteAOF(c *C) {
|
|
|
|
r := t.client.BgRewriteAOF()
|
|
|
|
c.Assert(r.Err(), IsNil)
|
|
|
|
c.Assert(r.Val(), Equals, "Background append only file rewriting started")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdBgSave(c *C) {
|
2012-08-20 00:59:52 +04:00
|
|
|
// workaround for "ERR Can't BGSAVE while AOF log rewriting is in progress"
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
2012-08-12 22:41:44 +04:00
|
|
|
r := t.client.BgSave()
|
2012-08-20 00:59:52 +04:00
|
|
|
c.Assert(r.Err(), IsNil)
|
|
|
|
c.Assert(r.Val(), Equals, "Background saving started")
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdClientKill(c *C) {
|
|
|
|
r := t.client.ClientKill("1.1.1.1:1111")
|
|
|
|
c.Assert(r.Err(), ErrorMatches, "ERR No such client")
|
|
|
|
c.Assert(r.Val(), Equals, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdClientList(c *C) {
|
|
|
|
r := t.client.ClientList()
|
|
|
|
c.Assert(r.Err(), IsNil)
|
|
|
|
c.Assert(
|
|
|
|
r.Val(),
|
|
|
|
Matches,
|
2012-08-16 00:48:32 +04:00
|
|
|
"addr=127.0.0.1:[0-9]+ .+\n",
|
2012-08-12 22:41:44 +04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdConfigGet(c *C) {
|
|
|
|
r := t.client.ConfigGet("*")
|
|
|
|
c.Assert(r.Err(), IsNil)
|
|
|
|
c.Assert(len(r.Val()) > 0, Equals, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdConfigResetStat(c *C) {
|
|
|
|
r := t.client.ConfigResetStat()
|
|
|
|
c.Assert(r.Err(), IsNil)
|
|
|
|
c.Assert(r.Val(), Equals, "OK")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdConfigSet(c *C) {
|
|
|
|
configGet := t.client.ConfigGet("maxmemory")
|
|
|
|
c.Assert(configGet.Err(), IsNil)
|
|
|
|
c.Assert(configGet.Val(), HasLen, 2)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(configGet.Val()[0], Equals, "maxmemory")
|
2012-08-12 22:41:44 +04:00
|
|
|
|
2012-08-20 01:16:26 +04:00
|
|
|
configSet := t.client.ConfigSet("maxmemory", configGet.Val()[1].(string))
|
2012-08-12 22:41:44 +04:00
|
|
|
c.Assert(configSet.Err(), IsNil)
|
|
|
|
c.Assert(configSet.Val(), Equals, "OK")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdDbSize(c *C) {
|
|
|
|
dbSize := t.client.DbSize()
|
|
|
|
c.Assert(dbSize.Err(), IsNil)
|
|
|
|
c.Assert(dbSize.Val(), Equals, int64(0))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdFlushAll(c *C) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdFlushDb(c *C) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdInfo(c *C) {
|
|
|
|
info := t.client.Info()
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(info.Err(), IsNil)
|
|
|
|
c.Assert(info.Val(), Not(Equals), "")
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdLastSave(c *C) {
|
|
|
|
lastSave := t.client.LastSave()
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(lastSave.Err(), IsNil)
|
|
|
|
c.Assert(lastSave.Val(), Not(Equals), 0)
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestCmdSave(c *C) {
|
|
|
|
save := t.client.Save()
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(save.Err(), IsNil)
|
|
|
|
c.Assert(save.Val(), Equals, "OK")
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestSlaveOf(c *C) {
|
|
|
|
slaveOf := t.client.SlaveOf("localhost", "8888")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(slaveOf.Err(), IsNil)
|
|
|
|
c.Assert(slaveOf.Val(), Equals, "OK")
|
2012-08-12 22:41:44 +04:00
|
|
|
|
|
|
|
slaveOf = t.client.SlaveOf("NO", "ONE")
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(slaveOf.Err(), IsNil)
|
|
|
|
c.Assert(slaveOf.Val(), Equals, "OK")
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestTime(c *C) {
|
|
|
|
time := t.client.Time()
|
2012-08-19 16:57:58 +04:00
|
|
|
c.Assert(time.Err(), IsNil)
|
|
|
|
c.Assert(time.Val(), HasLen, 2)
|
2012-08-12 22:41:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-20 14:42:33 +04:00
|
|
|
func (t *RedisTest) TestScriptingEval(c *C) {
|
|
|
|
eval := t.client.Eval(
|
|
|
|
"return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
|
|
|
|
[]string{"key1", "key2"},
|
|
|
|
[]string{"first", "second"},
|
|
|
|
)
|
|
|
|
c.Assert(eval.Err(), IsNil)
|
|
|
|
c.Assert(eval.Val(), DeepEquals, []interface{}{"key1", "key2", "first", "second"})
|
|
|
|
|
|
|
|
eval = t.client.Eval(
|
|
|
|
"return redis.call('set',KEYS[1],'bar')",
|
|
|
|
[]string{"foo"},
|
|
|
|
[]string{},
|
|
|
|
)
|
|
|
|
c.Assert(eval.Err(), IsNil)
|
|
|
|
c.Assert(eval.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
eval = t.client.Eval("return 10", []string{}, []string{})
|
|
|
|
c.Assert(eval.Err(), IsNil)
|
|
|
|
c.Assert(eval.Val(), Equals, int64(10))
|
|
|
|
|
|
|
|
eval = t.client.Eval("return {1,2,{3,'Hello World!'}}", []string{}, []string{})
|
|
|
|
c.Assert(eval.Err(), IsNil)
|
|
|
|
// DeepEquals can't compare nested slices.
|
|
|
|
c.Assert(
|
|
|
|
fmt.Sprintf("%#v", eval.Val()),
|
|
|
|
Equals,
|
|
|
|
`[]interface {}{1, 2, []interface {}{3, "Hello World!"}}`,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestScriptingEvalSha(c *C) {
|
|
|
|
set := t.client.Set("foo", "bar")
|
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
|
|
|
|
|
|
|
eval := t.client.Eval("return redis.call('get','foo')", []string{}, []string{})
|
|
|
|
c.Assert(eval.Err(), IsNil)
|
|
|
|
c.Assert(eval.Val(), Equals, "bar")
|
|
|
|
|
|
|
|
evalSha := t.client.EvalSha("6b1bf486c81ceb7edf3c093f4c48582e38c0e791", []string{}, []string{})
|
|
|
|
c.Assert(evalSha.Err(), IsNil)
|
|
|
|
c.Assert(evalSha.Val(), Equals, "bar")
|
|
|
|
|
|
|
|
evalSha = t.client.EvalSha("ffffffffffffffffffffffffffffffffffffffff", []string{}, []string{})
|
|
|
|
c.Assert(evalSha.Err(), ErrorMatches, "NOSCRIPT No matching script. Please use EVAL.")
|
|
|
|
c.Assert(evalSha.Val(), Equals, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestScriptingScriptExists(c *C) {
|
|
|
|
scriptLoad := t.client.ScriptLoad("return 1")
|
|
|
|
c.Assert(scriptLoad.Err(), IsNil)
|
|
|
|
c.Assert(scriptLoad.Val(), Equals, "e0e1f9fabfc9d4800c877a703b823ac0578ff8db")
|
|
|
|
|
|
|
|
scriptExists := t.client.ScriptExists(
|
|
|
|
"e0e1f9fabfc9d4800c877a703b823ac0578ff8db",
|
|
|
|
"ffffffffffffffffffffffffffffffffffffffff",
|
|
|
|
)
|
|
|
|
c.Assert(scriptExists.Err(), IsNil)
|
|
|
|
c.Assert(scriptExists.Val(), DeepEquals, []bool{true, false})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestScriptingScriptFlush(c *C) {
|
|
|
|
scriptFlush := t.client.ScriptFlush()
|
|
|
|
c.Assert(scriptFlush.Err(), IsNil)
|
|
|
|
c.Assert(scriptFlush.Val(), Equals, "OK")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestScriptingScriptKill(c *C) {
|
|
|
|
scriptKill := t.client.ScriptKill()
|
|
|
|
c.Assert(scriptKill.Err(), ErrorMatches, "ERR No scripts in execution right now.")
|
|
|
|
c.Assert(scriptKill.Val(), Equals, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RedisTest) TestScriptingScriptLoad(c *C) {
|
|
|
|
scriptLoad := t.client.ScriptLoad("return redis.call('get','foo')")
|
|
|
|
c.Assert(scriptLoad.Err(), IsNil)
|
|
|
|
c.Assert(scriptLoad.Val(), Equals, "6b1bf486c81ceb7edf3c093f4c48582e38c0e791")
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-07-27 15:43:30 +04:00
|
|
|
func (t *RedisTest) BenchmarkRedisPing(c *C) {
|
|
|
|
c.StopTimer()
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
runtime.LockOSThread()
|
|
|
|
t.client.ConnPool.(*redis.MultiConnPool).MaxCap = 1
|
|
|
|
|
2012-07-27 15:43:30 +04:00
|
|
|
for i := 0; i < 10; i++ {
|
2012-08-06 16:09:48 +04:00
|
|
|
ping := t.client.Ping()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(ping.Err(), IsNil)
|
|
|
|
c.Assert(ping.Val(), Equals, "PONG")
|
2012-07-27 15:43:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
c.StartTimer()
|
|
|
|
|
2012-07-25 17:00:50 +04:00
|
|
|
for i := 0; i < c.N; i++ {
|
2012-08-06 16:09:48 +04:00
|
|
|
t.client.Ping()
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-27 15:43:30 +04:00
|
|
|
func (t *RedisTest) BenchmarkRedisSet(c *C) {
|
|
|
|
c.StopTimer()
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
runtime.LockOSThread()
|
|
|
|
t.client.ConnPool.(*redis.MultiConnPool).MaxCap = 1
|
|
|
|
|
2012-07-27 15:43:30 +04:00
|
|
|
for i := 0; i < 10; i++ {
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
|
|
|
c.Assert(set.Val(), Equals, "OK")
|
2012-07-27 15:43:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
c.StartTimer()
|
|
|
|
|
2012-07-25 17:00:50 +04:00
|
|
|
for i := 0; i < c.N; i++ {
|
2012-08-17 22:36:48 +04:00
|
|
|
t.client.Set("key", "hello")
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-05 22:09:38 +04:00
|
|
|
func (t *RedisTest) BenchmarkRedisGetNil(c *C) {
|
2012-07-27 15:43:30 +04:00
|
|
|
c.StopTimer()
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
runtime.LockOSThread()
|
|
|
|
t.client.ConnPool.(*redis.MultiConnPool).MaxCap = 1
|
|
|
|
|
2012-07-27 15:43:30 +04:00
|
|
|
for i := 0; i < 10; i++ {
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), Equals, redis.Nil)
|
|
|
|
c.Assert(get.Val(), Equals, "")
|
2012-07-27 15:43:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
c.StartTimer()
|
|
|
|
|
2012-07-25 17:00:50 +04:00
|
|
|
for i := 0; i < c.N; i++ {
|
2012-08-17 22:36:48 +04:00
|
|
|
t.client.Get("key")
|
2012-07-25 17:00:50 +04:00
|
|
|
}
|
|
|
|
}
|
2012-07-27 15:43:30 +04:00
|
|
|
|
2012-08-05 22:09:38 +04:00
|
|
|
func (t *RedisTest) BenchmarkRedisGet(c *C) {
|
|
|
|
c.StopTimer()
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
runtime.LockOSThread()
|
|
|
|
t.client.ConnPool.(*redis.MultiConnPool).MaxCap = 1
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
set := t.client.Set("key", "hello")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(set.Err(), IsNil)
|
2012-08-05 22:09:38 +04:00
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
2012-08-17 22:36:48 +04:00
|
|
|
get := t.client.Get("key")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(get.Err(), IsNil)
|
2012-08-17 22:36:48 +04:00
|
|
|
c.Assert(get.Val(), Equals, "hello")
|
2012-08-05 22:09:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
c.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < c.N; i++ {
|
2012-08-17 22:36:48 +04:00
|
|
|
t.client.Get("key")
|
2012-08-05 22:09:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-06 12:33:49 +04:00
|
|
|
func (t *RedisTest) BenchmarkRedisMGet(c *C) {
|
|
|
|
c.StopTimer()
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
runtime.LockOSThread()
|
|
|
|
t.client.ConnPool.(*redis.MultiConnPool).MaxCap = 1
|
|
|
|
|
2012-08-17 22:36:48 +04:00
|
|
|
mSet := t.client.MSet("key1", "hello1", "key2", "hello2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(mSet.Err(), IsNil)
|
2012-08-06 12:33:49 +04:00
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
2012-08-17 22:36:48 +04:00
|
|
|
mGet := t.client.MGet("key1", "key2")
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(mGet.Err(), IsNil)
|
2012-08-20 00:59:52 +04:00
|
|
|
c.Assert(mGet.Val(), DeepEquals, []interface{}{"hello1", "hello2"})
|
2012-08-06 12:33:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
c.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < c.N; i++ {
|
2012-08-17 22:36:48 +04:00
|
|
|
t.client.MGet("key1", "key2")
|
2012-08-06 12:33:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-27 15:43:30 +04:00
|
|
|
func (t *RedisTest) BenchmarkRedisWriteRead(c *C) {
|
|
|
|
c.StopTimer()
|
|
|
|
|
2012-08-13 15:45:32 +04:00
|
|
|
runtime.LockOSThread()
|
|
|
|
|
2012-08-05 16:09:43 +04:00
|
|
|
conn, _, err := t.client.ConnPool.Get()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
2012-07-27 15:43:30 +04:00
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
2012-08-14 19:20:22 +04:00
|
|
|
err := t.client.WriteReq(conn, redis.NewStatusReq("PING"))
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
2012-08-09 14:12:41 +04:00
|
|
|
|
|
|
|
line, _, err := conn.Rd.ReadLine()
|
2012-08-11 18:42:10 +04:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
c.Assert(line, DeepEquals, []byte("+PONG"))
|
2012-07-27 15:43:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
c.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < c.N; i++ {
|
2012-08-14 19:20:22 +04:00
|
|
|
t.client.WriteReq(conn, redis.NewStatusReq("PING"))
|
2012-08-09 14:12:41 +04:00
|
|
|
conn.Rd.ReadLine()
|
2012-07-27 15:43:30 +04:00
|
|
|
}
|
2012-08-05 22:09:38 +04:00
|
|
|
|
|
|
|
c.StopTimer()
|
|
|
|
t.client.ConnPool.Add(conn)
|
|
|
|
c.StartTimer()
|
2012-07-27 15:43:30 +04:00
|
|
|
}
|