diff --git a/README.md b/README.md index 730c4442..197442eb 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,13 @@ Install: go get github.com/vmihailenco/redis +Contributing +------------ + +Configure Redis to allow maximum 10 clients: + + maxclients 10 + Run tests: go test -gocheck.v diff --git a/commands.go b/commands.go index a179d7d3..7f1fa023 100644 --- a/commands.go +++ b/commands.go @@ -1,7 +1,6 @@ package redis import ( - "fmt" "strconv" ) @@ -843,138 +842,3 @@ func (c *Client) ZUnionStore( c.Process(req) return req } - -//------------------------------------------------------------------------------ - -func (c *Client) PubSubClient() (*PubSubClient, error) { - return newPubSubClient(c) -} - -func (c *Client) Publish(channel, message string) *IntReq { - req := NewIntReq("PUBLISH", channel, message) - c.Process(req) - return req -} - -//------------------------------------------------------------------------------ - -func (c *Client) PipelineClient() (*Client, error) { - return &Client{ - ConnPool: c.ConnPool, - InitConn: c.InitConn, - reqs: make([]Req, 0), - }, nil -} - -//------------------------------------------------------------------------------ - -func (c *Client) MultiClient() (*Client, error) { - return &Client{ - ConnPool: NewSingleConnPool(c.ConnPool), - InitConn: c.InitConn, - }, nil -} - -func (c *Client) Multi() { - c.reqs = make([]Req, 0) -} - -func (c *Client) Watch(keys ...string) *StatusReq { - args := append([]string{"WATCH"}, keys...) - req := NewStatusReq(args...) - c.Process(req) - return req -} - -func (c *Client) Unwatch(keys ...string) *StatusReq { - args := append([]string{"UNWATCH"}, keys...) - req := NewStatusReq(args...) - c.Process(req) - return req -} - -func (c *Client) Discard() { - c.mtx.Lock() - c.reqs = c.reqs[:0] - c.mtx.Unlock() -} - -func (c *Client) Exec() ([]Req, error) { - c.mtx.Lock() - if len(c.reqs) == 0 { - c.mtx.Unlock() - return c.reqs, nil - } - reqs := c.reqs - c.reqs = nil - c.mtx.Unlock() - - conn, err := c.conn() - if err != nil { - return nil, err - } - - err = c.ExecReqs(reqs, conn) - if err != nil { - c.ConnPool.Remove(conn) - return nil, err - } - - c.ConnPool.Add(conn) - return reqs, nil -} - -func (c *Client) ExecReqs(reqs []Req, conn *Conn) error { - multiReq := make([]byte, 0, 1024) - multiReq = append(multiReq, PackReq([]string{"MULTI"})...) - for _, req := range reqs { - multiReq = append(multiReq, req.Req()...) - } - multiReq = append(multiReq, PackReq([]string{"EXEC"})...) - - err := c.WriteReq(multiReq, conn) - if err != nil { - return err - } - - statusReq := NewStatusReq() - - // Parse MULTI command reply. - _, err = statusReq.ParseReply(conn.Rd) - if err != nil { - return err - } - - // Parse queued replies. - for _ = range reqs { - _, err = statusReq.ParseReply(conn.Rd) - if err != nil { - return err - } - } - - // Parse number of replies. - line, err := readLine(conn.Rd) - if err != nil { - return err - } - if line[0] != '*' { - return fmt.Errorf("Expected '*', but got line %q", line) - } - if isNilReplies(line) { - return Nil - } - - // Parse replies. - for i := 0; i < len(reqs); i++ { - req := reqs[i] - val, err := req.ParseReply(conn.Rd) - if err != nil { - req.SetErr(err) - } else { - req.SetVal(val) - } - } - - return nil -} diff --git a/connpool.go b/connpool.go index 27cb3201..80f640b0 100644 --- a/connpool.go +++ b/connpool.go @@ -9,11 +9,11 @@ import ( ) type Conn struct { - RW io.ReadWriter + RW io.ReadWriteCloser Rd *bufio.Reader } -func NewConn(rw io.ReadWriter) *Conn { +func NewConn(rw io.ReadWriteCloser) *Conn { return &Conn{ RW: rw, Rd: bufio.NewReaderSize(rw, 1024), @@ -22,10 +22,10 @@ func NewConn(rw io.ReadWriter) *Conn { type ConnPool interface { Get() (*Conn, bool, error) - Add(*Conn) - Remove(*Conn) + Add(*Conn) error + Remove(*Conn) error Len() int - Close() + Close() error } //------------------------------------------------------------------------------ @@ -36,10 +36,10 @@ type MultiConnPool struct { conns []*Conn OpenConn OpenConnFunc CloseConn CloseConnFunc - cap, MaxCap int64 + cap, MaxCap int } -func NewMultiConnPool(openConn OpenConnFunc, closeConn CloseConnFunc, maxCap int64) *MultiConnPool { +func NewMultiConnPool(openConn OpenConnFunc, closeConn CloseConnFunc, maxCap int) *MultiConnPool { logger := log.New( os.Stdout, "redis.connpool: ", @@ -81,47 +81,74 @@ func (p *MultiConnPool) Get() (*Conn, bool, error) { return conn, false, nil } -func (p *MultiConnPool) Add(conn *Conn) { +func (p *MultiConnPool) Add(conn *Conn) error { p.cond.L.Lock() defer p.cond.L.Unlock() p.conns = append(p.conns, conn) p.cond.Signal() + return nil } -func (p *MultiConnPool) Remove(conn *Conn) { - p.cond.L.Lock() - p.cap-- - p.cond.Signal() - p.cond.L.Unlock() - - if p.CloseConn != nil && conn != nil { - p.CloseConn(conn.RW) +func (p *MultiConnPool) Remove(conn *Conn) error { + defer func() { + p.cond.L.Lock() + p.cap-- + p.cond.Signal() + p.cond.L.Unlock() + }() + if conn == nil { + return nil } + return p.closeConn(conn) } func (p *MultiConnPool) Len() int { return len(p.conns) } -func (p *MultiConnPool) Close() {} +func (p *MultiConnPool) Close() error { + p.cond.L.Lock() + defer p.cond.L.Unlock() + for _, conn := range p.conns { + err := p.closeConn(conn) + if err != nil { + return err + } + } + p.conns = make([]*Conn, 0) + p.cap = 0 + return nil +} + +func (p *MultiConnPool) closeConn(conn *Conn) error { + if p.CloseConn != nil { + err := p.CloseConn(conn.RW) + if err != nil { + return err + } + } + return conn.RW.Close() +} //------------------------------------------------------------------------------ type SingleConnPool struct { - mtx sync.Mutex - pool ConnPool - conn *Conn + mtx sync.Mutex + pool ConnPool + conn *Conn + isReusable bool } -func NewSingleConnPoolConn(pool ConnPool, conn *Conn) *SingleConnPool { +func NewSingleConnPoolConn(pool ConnPool, conn *Conn, isReusable bool) *SingleConnPool { return &SingleConnPool{ - pool: pool, - conn: conn, + pool: pool, + conn: conn, + isReusable: isReusable, } } -func NewSingleConnPool(pool ConnPool) *SingleConnPool { - return NewSingleConnPoolConn(pool, nil) +func NewSingleConnPool(pool ConnPool, isReusable bool) *SingleConnPool { + return NewSingleConnPoolConn(pool, nil, isReusable) } func (p *SingleConnPool) Get() (*Conn, bool, error) { @@ -138,17 +165,32 @@ func (p *SingleConnPool) Get() (*Conn, bool, error) { return p.conn, isNew, nil } -func (p *SingleConnPool) Add(conn *Conn) {} +func (p *SingleConnPool) Add(conn *Conn) error { + return nil +} -func (p *SingleConnPool) Remove(conn *Conn) {} +func (p *SingleConnPool) Remove(conn *Conn) error { + return nil +} func (p *SingleConnPool) Len() int { return 1 } -func (p *SingleConnPool) Close() { +func (p *SingleConnPool) Close() error { p.mtx.Lock() defer p.mtx.Unlock() - p.pool.Add(p.conn) + + if p.conn == nil { + return nil + } + + var err error + if p.isReusable { + err = p.pool.Add(p.conn) + } else { + err = p.pool.Remove(p.conn) + } p.conn = nil + return err } diff --git a/multi.go b/multi.go new file mode 100644 index 00000000..cb58e52e --- /dev/null +++ b/multi.go @@ -0,0 +1,124 @@ +package redis + +import ( + "fmt" +) + +type MultiClient struct { + *Client +} + +func (c *Client) MultiClient() (*MultiClient, error) { + return &MultiClient{ + Client: &Client{ + BaseClient: &BaseClient{ + ConnPool: NewSingleConnPool(c.ConnPool, true), + InitConn: c.InitConn, + }, + }, + }, nil +} + +func (c *MultiClient) Multi() { + c.reqs = make([]Req, 0) +} + +func (c *MultiClient) Watch(keys ...string) *StatusReq { + args := append([]string{"WATCH"}, keys...) + req := NewStatusReq(args...) + c.Process(req) + return req +} + +func (c *MultiClient) Unwatch(keys ...string) *StatusReq { + args := append([]string{"UNWATCH"}, keys...) + req := NewStatusReq(args...) + c.Process(req) + return req +} + +func (c *MultiClient) Discard() { + c.mtx.Lock() + c.reqs = c.reqs[:0] + c.mtx.Unlock() +} + +func (c *MultiClient) Exec() ([]Req, error) { + c.mtx.Lock() + if len(c.reqs) == 0 { + c.mtx.Unlock() + return c.reqs, nil + } + reqs := c.reqs + c.reqs = nil + c.mtx.Unlock() + + conn, err := c.conn() + if err != nil { + return nil, err + } + + err = c.ExecReqs(reqs, conn) + if err != nil { + c.ConnPool.Remove(conn) + return nil, err + } + + c.ConnPool.Add(conn) + return reqs, nil +} + +func (c *MultiClient) ExecReqs(reqs []Req, conn *Conn) error { + multiReq := make([]byte, 0, 1024) + multiReq = append(multiReq, PackReq([]string{"MULTI"})...) + for _, req := range reqs { + multiReq = append(multiReq, req.Req()...) + } + multiReq = append(multiReq, PackReq([]string{"EXEC"})...) + + err := c.WriteReq(multiReq, conn) + if err != nil { + return err + } + + statusReq := NewStatusReq() + + // Parse MULTI command reply. + _, err = statusReq.ParseReply(conn.Rd) + if err != nil { + return err + } + + // Parse queued replies. + for _ = range reqs { + _, err = statusReq.ParseReply(conn.Rd) + if err != nil { + return err + } + } + + // Parse number of replies. + line, err := readLine(conn.Rd) + if err != nil { + return err + } + if line[0] != '*' { + return fmt.Errorf("Expected '*', but got line %q", line) + } + if isNilReplies(line) { + return Nil + } + + // Parse replies. + for i := 0; i < len(reqs); i++ { + req := reqs[i] + val, err := req.ParseReply(conn.Rd) + if err != nil { + req.SetErr(err) + } else { + req.SetVal(val) + } + } + + return nil +} diff --git a/pipeline.go b/pipeline.go new file mode 100644 index 00000000..89ed0f28 --- /dev/null +++ b/pipeline.go @@ -0,0 +1,75 @@ +package redis + +type PipelineClient struct { + *Client +} + +func (c *Client) PipelineClient() (*PipelineClient, error) { + return &PipelineClient{ + Client: &Client{ + BaseClient: &BaseClient{ + ConnPool: c.ConnPool, + InitConn: c.InitConn, + reqs: make([]Req, 0), + }, + }, + }, nil +} + +func (c *PipelineClient) Close() error { + return nil +} + +func (c *PipelineClient) RunQueued() ([]Req, error) { + c.mtx.Lock() + if len(c.reqs) == 0 { + c.mtx.Unlock() + return c.reqs, nil + } + reqs := c.reqs + c.reqs = make([]Req, 0) + c.mtx.Unlock() + + conn, err := c.conn() + if err != nil { + return nil, err + } + + err = c.RunReqs(reqs, conn) + if err != nil { + c.ConnPool.Remove(conn) + return nil, err + } + + c.ConnPool.Add(conn) + return reqs, nil +} + +func (c *PipelineClient) RunReqs(reqs []Req, conn *Conn) error { + var multiReq []byte + if len(reqs) == 1 { + multiReq = reqs[0].Req() + } else { + multiReq = make([]byte, 0, 1024) + for _, req := range reqs { + multiReq = append(multiReq, req.Req()...) + } + } + + err := c.WriteReq(multiReq, conn) + if err != nil { + return err + } + + for i := 0; i < len(reqs); i++ { + req := reqs[i] + val, err := req.ParseReply(conn.Rd) + if err != nil { + req.SetErr(err) + } else { + req.SetVal(val) + } + } + + return nil +} diff --git a/pubsub.go b/pubsub.go index 8f738b97..11d2d5f3 100644 --- a/pubsub.go +++ b/pubsub.go @@ -6,19 +6,29 @@ import ( ) type PubSubClient struct { - *Client + *BaseClient ch chan *Message once sync.Once } func newPubSubClient(client *Client) (*PubSubClient, error) { - c := &PubSubClient{ - Client: &Client{ - ConnPool: NewSingleConnPool(client.ConnPool), + return &PubSubClient{ + BaseClient: &BaseClient{ + ConnPool: NewSingleConnPool(client.ConnPool, false), + InitConn: client.InitConn, }, ch: make(chan *Message), - } - return c, nil + }, nil +} + +func (c *Client) PubSubClient() (*PubSubClient, error) { + return newPubSubClient(c) +} + +func (c *Client) Publish(channel, message string) *IntReq { + req := NewIntReq("PUBLISH", channel, message) + c.Process(req) + return req } type Message struct { @@ -28,12 +38,7 @@ type Message struct { Err error } -func (c *PubSubClient) consumeMessages() { - conn, err := c.conn() - // SignleConnPool never returns error. - if err != nil { - panic(err) - } +func (c *PubSubClient) consumeMessages(conn *Conn) { req := NewMultiBulkReq() for { @@ -89,7 +94,7 @@ func (c *PubSubClient) subscribe(cmd string, channels ...string) (chan *Message, } c.once.Do(func() { - go c.consumeMessages() + go c.consumeMessages(conn) }) return c.ch, nil diff --git a/redis.go b/redis.go index a198af67..ef0e2913 100644 --- a/redis.go +++ b/redis.go @@ -12,18 +12,18 @@ var ( ErrReaderTooSmall = errors.New("redis: Reader is too small") ) -type OpenConnFunc func() (io.ReadWriter, error) -type CloseConnFunc func(io.ReadWriter) +type OpenConnFunc func() (io.ReadWriteCloser, error) +type CloseConnFunc func(io.ReadWriteCloser) error type InitConnFunc func(*Client) error func TCPConnector(addr string) OpenConnFunc { - return func() (io.ReadWriter, error) { + return func() (io.ReadWriteCloser, error) { return net.Dial("tcp", addr) } } func TLSConnector(addr string, tlsConfig *tls.Config) OpenConnFunc { - return func() (io.ReadWriter, error) { + return func() (io.ReadWriteCloser, error) { return tls.Dial("tcp", addr, tlsConfig) } } @@ -54,45 +54,29 @@ func AuthSelectFunc(password string, db int64) InitConnFunc { //------------------------------------------------------------------------------ -type Client struct { +type BaseClient struct { mtx sync.Mutex ConnPool ConnPool InitConn InitConnFunc - - reqs []Req + reqs []Req } -func NewClient(openConn OpenConnFunc, closeConn CloseConnFunc, initConn InitConnFunc) *Client { - return &Client{ - ConnPool: NewMultiConnPool(openConn, closeConn, 10), - InitConn: initConn, - } +func (c *BaseClient) WriteReq(buf []byte, conn *Conn) error { + _, err := conn.RW.Write(buf) + return err } -func NewTCPClient(addr string, password string, db int64) *Client { - return NewClient(TCPConnector(addr), nil, AuthSelectFunc(password, db)) -} - -func NewTLSClient(addr string, tlsConfig *tls.Config, password string, db int64) *Client { - return NewClient( - TLSConnector(addr, tlsConfig), - nil, - AuthSelectFunc(password, db), - ) -} - -func (c *Client) Close() { - c.ConnPool.Close() -} - -func (c *Client) conn() (*Conn, error) { +func (c *BaseClient) conn() (*Conn, error) { conn, isNew, err := c.ConnPool.Get() if err != nil { return nil, err } + if isNew && c.InitConn != nil { client := &Client{ - ConnPool: NewSingleConnPoolConn(c.ConnPool, conn), + BaseClient: &BaseClient{ + ConnPool: NewSingleConnPoolConn(c.ConnPool, conn, true), + }, } err = c.InitConn(client) if err != nil { @@ -102,12 +86,7 @@ func (c *Client) conn() (*Conn, error) { return conn, nil } -func (c *Client) WriteReq(buf []byte, conn *Conn) error { - _, err := conn.RW.Write(buf) - return err -} - -func (c *Client) Process(req Req) { +func (c *BaseClient) Process(req Req) { if c.reqs == nil { c.Run(req) } else { @@ -115,13 +94,7 @@ func (c *Client) Process(req Req) { } } -func (c *Client) Queue(req Req) { - c.mtx.Lock() - c.reqs = append(c.reqs, req) - c.mtx.Unlock() -} - -func (c *Client) Run(req Req) { +func (c *BaseClient) Run(req Req) { conn, err := c.conn() if err != nil { req.SetErr(err) @@ -146,56 +119,39 @@ func (c *Client) Run(req Req) { req.SetVal(val) } -func (c *Client) RunQueued() ([]Req, error) { +func (c *BaseClient) Queue(req Req) { c.mtx.Lock() - if len(c.reqs) == 0 { - c.mtx.Unlock() - return c.reqs, nil - } - reqs := c.reqs - c.reqs = make([]Req, 0) + c.reqs = append(c.reqs, req) c.mtx.Unlock() - - conn, err := c.conn() - if err != nil { - return nil, err - } - - err = c.RunReqs(reqs, conn) - if err != nil { - c.ConnPool.Remove(conn) - return nil, err - } - - c.ConnPool.Add(conn) - return reqs, nil } -func (c *Client) RunReqs(reqs []Req, conn *Conn) error { - var multiReq []byte - if len(reqs) == 1 { - multiReq = reqs[0].Req() - } else { - multiReq = make([]byte, 0, 1024) - for _, req := range reqs { - multiReq = append(multiReq, req.Req()...) - } - } - - err := c.WriteReq(multiReq, conn) - if err != nil { - return err - } - - for i := 0; i < len(reqs); i++ { - req := reqs[i] - val, err := req.ParseReply(conn.Rd) - if err != nil { - req.SetErr(err) - } else { - req.SetVal(val) - } - } - - return nil +func (c *BaseClient) Close() error { + return c.ConnPool.Close() +} + +//------------------------------------------------------------------------------ + +type Client struct { + *BaseClient +} + +func NewClient(openConn OpenConnFunc, closeConn CloseConnFunc, initConn InitConnFunc) *Client { + return &Client{ + BaseClient: &BaseClient{ + ConnPool: NewMultiConnPool(openConn, closeConn, 10), + InitConn: initConn, + }, + } +} + +func NewTCPClient(addr string, password string, db int64) *Client { + return NewClient(TCPConnector(addr), nil, AuthSelectFunc(password, db)) +} + +func NewTLSClient(addr string, tlsConfig *tls.Config, password string, db int64) *Client { + return NewClient( + TLSConnector(addr, tlsConfig), + nil, + AuthSelectFunc(password, db), + ) } diff --git a/redis_test.go b/redis_test.go index 7637e275..e4c9f09f 100644 --- a/redis_test.go +++ b/redis_test.go @@ -13,12 +13,13 @@ import ( "github.com/vmihailenco/redis" ) -const redisAddr = ":8888" +const redisAddr = ":6379" //------------------------------------------------------------------------------ type RedisTest struct { - client *redis.Client + openedConnsCount, closedConnsCount int64 + client *redis.Client } var _ = Suite(&RedisTest{}) @@ -28,18 +29,30 @@ func Test(t *testing.T) { TestingT(t) } //------------------------------------------------------------------------------ func (t *RedisTest) SetUpTest(c *C) { - t.client = redis.NewTCPClient(redisAddr, "", -1) - c.Check(t.client.Flushdb().Err(), IsNil) + t.openedConnsCount = 0 + openConn := func() (io.ReadWriteCloser, error) { + t.openedConnsCount++ + return net.Dial("tcp", redisAddr) + } + t.closedConnsCount = 0 + closeConn := func(conn io.ReadWriteCloser) error { + t.closedConnsCount++ + return nil + } + t.client = redis.NewClient(openConn, closeConn, nil) + c.Assert(t.client.Flushdb().Err(), IsNil) } func (t *RedisTest) TearDownTest(c *C) { - c.Check(t.client.Flushdb().Err(), IsNil) + c.Assert(t.client.Flushdb().Err(), IsNil) + c.Assert(t.client.Close(), IsNil) + c.Assert(t.openedConnsCount, Equals, t.closedConnsCount) } //------------------------------------------------------------------------------ func (t *RedisTest) TestInitConn(c *C) { - openConn := func() (io.ReadWriter, error) { + openConn := func() (io.ReadWriteCloser, error) { return net.Dial("tcp", redisAddr) } @@ -50,21 +63,146 @@ func (t *RedisTest) TestInitConn(c *C) { } client := redis.NewClient(openConn, nil, initConn) + defer func() { + c.Assert(client.Close(), IsNil) + }() + ping := client.Ping() - c.Check(ping.Err(), IsNil) - c.Check(ping.Val(), Equals, "PONG") - c.Check(isInitConnCalled, Equals, true) + c.Assert(ping.Err(), IsNil) + c.Assert(ping.Val(), Equals, "PONG") + c.Assert(isInitConnCalled, Equals, true) } func (t *RedisTest) TestRunWithouthCheckingErrVal(c *C) { set := t.client.Set("foo", "bar") get := t.client.Get("foo") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "bar") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") +} + +//------------------------------------------------------------------------------ + +func (t *RedisTest) TestConnPoolMaxCap(c *C) { + 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) + c.Assert(t.openedConnsCount, Equals, int64(10)) + c.Assert(t.closedConnsCount, Equals, int64(10)) +} + +func (t *RedisTest) TestConnPoolMaxCapOnPipelineClient(c *C) { + 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) + c.Assert(t.openedConnsCount, Equals, int64(10)) + c.Assert(t.closedConnsCount, Equals, int64(10)) +} + +func (t *RedisTest) TestConnPoolMaxCapOnMultiClient(c *C) { + wg := &sync.WaitGroup{} + for i := 0; i < 1000; i++ { + wg.Add(1) + go func() { + multi, err := t.client.MultiClient() + c.Assert(err, IsNil) + + multi.Multi() + + ping := multi.Ping() + reqs, err := multi.Exec() + 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) + c.Assert(t.openedConnsCount, Equals, int64(10)) + c.Assert(t.closedConnsCount, Equals, int64(10)) +} + +func (t *RedisTest) TestConnPoolMaxCapOnPubSubClient(c *C) { + 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) + c.Assert(t.openedConnsCount, Equals, int64(1000)) + c.Assert(t.closedConnsCount, Equals, int64(1000)) +} + +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() { + c.Check(client.Close(), IsNil) + }() + + 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") } //------------------------------------------------------------------------------ @@ -75,20 +213,20 @@ func (t *RedisTest) TestAuth(c *C) { func (t *RedisTest) TestEcho(c *C) { echo := t.client.Echo("hello") - c.Check(echo.Err(), IsNil) - c.Check(echo.Val(), Equals, "hello") + c.Assert(echo.Err(), IsNil) + c.Assert(echo.Val(), Equals, "hello") } func (t *RedisTest) TestPing(c *C) { ping := t.client.Ping() - c.Check(ping.Err(), IsNil) - c.Check(ping.Val(), Equals, "PONG") + c.Assert(ping.Err(), IsNil) + c.Assert(ping.Val(), Equals, "PONG") } func (t *RedisTest) TestSelect(c *C) { sel := t.client.Select(1) - c.Check(sel.Err(), IsNil) - c.Check(sel.Val(), Equals, "OK") + c.Assert(sel.Err(), IsNil) + c.Assert(sel.Val(), Equals, "OK") } // //------------------------------------------------------------------------------ @@ -98,8 +236,8 @@ func (t *RedisTest) TestDel(c *C) { t.client.Set("key2", "World") del := t.client.Del("key1", "key2", "key3") - c.Check(del.Err(), IsNil) - c.Check(del.Val(), Equals, int64(2)) + c.Assert(del.Err(), IsNil) + c.Assert(del.Val(), Equals, int64(2)) } func (t *RedisTest) TestDump(c *C) { @@ -110,64 +248,64 @@ func (t *RedisTest) TestExists(c *C) { t.client.Set("key1", "Hello") exists := t.client.Exists("key1") - c.Check(exists.Err(), IsNil) - c.Check(exists.Val(), Equals, true) + c.Assert(exists.Err(), IsNil) + c.Assert(exists.Val(), Equals, true) exists = t.client.Exists("key2") - c.Check(exists.Err(), IsNil) - c.Check(exists.Val(), Equals, false) + c.Assert(exists.Err(), IsNil) + c.Assert(exists.Val(), Equals, false) } func (t *RedisTest) TestExpire(c *C) { t.client.Set("key", "Hello") expire := t.client.Expire("key", 10) - c.Check(expire.Err(), IsNil) - c.Check(expire.Val(), Equals, true) + c.Assert(expire.Err(), IsNil) + c.Assert(expire.Val(), Equals, true) ttl := t.client.TTL("key") - c.Check(ttl.Err(), IsNil) - c.Check(ttl.Val(), Equals, int64(10)) + c.Assert(ttl.Err(), IsNil) + c.Assert(ttl.Val(), Equals, int64(10)) set := t.client.Set("key", "Hello World") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") ttl = t.client.TTL("key") - c.Check(ttl.Err(), IsNil) - c.Check(ttl.Val(), Equals, int64(-1)) + c.Assert(ttl.Err(), IsNil) + c.Assert(ttl.Val(), Equals, int64(-1)) } func (t *RedisTest) TestExpireAt(c *C) { t.client.Set("key", "Hello") exists := t.client.Exists("key") - c.Check(exists.Err(), IsNil) - c.Check(exists.Val(), Equals, true) + c.Assert(exists.Err(), IsNil) + c.Assert(exists.Val(), Equals, true) expireAt := t.client.ExpireAt("key", 1293840000) - c.Check(expireAt.Err(), IsNil) - c.Check(expireAt.Val(), Equals, true) + c.Assert(expireAt.Err(), IsNil) + c.Assert(expireAt.Val(), Equals, true) exists = t.client.Exists("key") - c.Check(exists.Err(), IsNil) - c.Check(exists.Val(), Equals, false) + c.Assert(exists.Err(), IsNil) + c.Assert(exists.Val(), Equals, false) } func (t *RedisTest) TestKeys(c *C) { t.client.MSet("one", "1", "two", "2", "three", "3", "four", "4") keys := t.client.Keys("*o*") - c.Check(keys.Err(), IsNil) - c.Check(keys.Val(), DeepEquals, []interface{}{"four", "two", "one"}) + c.Assert(keys.Err(), IsNil) + c.Assert(keys.Val(), DeepEquals, []interface{}{"four", "two", "one"}) keys = t.client.Keys("t??") - c.Check(keys.Err(), IsNil) - c.Check(keys.Val(), DeepEquals, []interface{}{"two"}) + c.Assert(keys.Err(), IsNil) + c.Assert(keys.Val(), DeepEquals, []interface{}{"two"}) keys = t.client.Keys("*") - c.Check(keys.Err(), IsNil) - c.Check(keys.Val(), DeepEquals, []interface{}{"four", "three", "two", "one"}) + c.Assert(keys.Err(), IsNil) + c.Assert(keys.Val(), DeepEquals, []interface{}{"four", "three", "two", "one"}) } func (t *RedisTest) TestMigrate(c *C) { @@ -176,166 +314,166 @@ func (t *RedisTest) TestMigrate(c *C) { func (t *RedisTest) TestMove(c *C) { move := t.client.Move("foo", 1) - c.Check(move.Err(), IsNil) - c.Check(move.Val(), Equals, false) + c.Assert(move.Err(), IsNil) + c.Assert(move.Val(), Equals, false) set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") move = t.client.Move("foo", 1) - c.Check(move.Err(), IsNil) - c.Check(move.Val(), Equals, true) + c.Assert(move.Err(), IsNil) + c.Assert(move.Val(), Equals, true) get := t.client.Get("foo") - c.Check(get.Err(), Equals, redis.Nil) - c.Check(get.Val(), Equals, "") + c.Assert(get.Err(), Equals, redis.Nil) + c.Assert(get.Val(), Equals, "") sel := t.client.Select(1) - c.Check(sel.Err(), IsNil) - c.Check(sel.Val(), Equals, "OK") + c.Assert(sel.Err(), IsNil) + c.Assert(sel.Val(), Equals, "OK") get = t.client.Get("foo") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "bar") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "bar") } func (t *RedisTest) TestObject(c *C) { set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") refCount := t.client.ObjectRefCount("foo") - c.Check(refCount.Err(), IsNil) - c.Check(refCount.Val(), Equals, int64(1)) + c.Assert(refCount.Err(), IsNil) + c.Assert(refCount.Val(), Equals, int64(1)) enc := t.client.ObjectEncoding("foo") - c.Check(enc.Err(), IsNil) - c.Check(enc.Val(), Equals, "raw") + c.Assert(enc.Err(), IsNil) + c.Assert(enc.Val(), Equals, "raw") idleTime := t.client.ObjectIdleTime("foo") - c.Check(idleTime.Err(), IsNil) - c.Check(idleTime.Val(), Equals, int64(0)) + c.Assert(idleTime.Err(), IsNil) + c.Assert(idleTime.Val(), Equals, int64(0)) } func (t *RedisTest) TestPersist(c *C) { set := t.client.Set("key", "Hello") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") expire := t.client.Expire("key", 10) - c.Check(expire.Err(), IsNil) - c.Check(expire.Val(), Equals, true) + c.Assert(expire.Err(), IsNil) + c.Assert(expire.Val(), Equals, true) ttl := t.client.TTL("key") - c.Check(ttl.Err(), IsNil) - c.Check(ttl.Val(), Equals, int64(10)) + c.Assert(ttl.Err(), IsNil) + c.Assert(ttl.Val(), Equals, int64(10)) persist := t.client.Persist("key") - c.Check(persist.Err(), IsNil) - c.Check(persist.Val(), Equals, true) + c.Assert(persist.Err(), IsNil) + c.Assert(persist.Val(), Equals, true) ttl = t.client.TTL("key") - c.Check(ttl.Err(), IsNil) - c.Check(ttl.Val(), Equals, int64(-1)) + c.Assert(ttl.Err(), IsNil) + c.Assert(ttl.Val(), Equals, int64(-1)) } func (t *RedisTest) TestPExpire(c *C) { c.Skip("not implemented") set := t.client.Set("key", "Hello") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") pexpire := t.client.PExpire("key", 1500) - c.Check(pexpire.Err(), IsNil) - c.Check(pexpire.Val(), Equals, true) + c.Assert(pexpire.Err(), IsNil) + c.Assert(pexpire.Val(), Equals, true) ttl := t.client.TTL("key") - c.Check(ttl.Err(), IsNil) - c.Check(ttl.Val(), Equals, 1) + c.Assert(ttl.Err(), IsNil) + c.Assert(ttl.Val(), Equals, 1) pttl := t.client.PTTL("key") - c.Check(pttl.Err(), IsNil) - c.Check(pttl.Val(), Equals, 1500) + c.Assert(pttl.Err(), IsNil) + c.Assert(pttl.Val(), Equals, 1500) } func (t *RedisTest) TestPExpireAt(c *C) { c.Skip("not implemented") set := t.client.Set("key", "Hello") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") pExpireAt := t.client.PExpireAt("key", 1555555555005) - c.Check(pExpireAt.Err(), IsNil) - c.Check(pExpireAt.Val(), Equals, true) + c.Assert(pExpireAt.Err(), IsNil) + c.Assert(pExpireAt.Val(), Equals, true) ttl := t.client.TTL("key") - c.Check(ttl.Err(), IsNil) - c.Check(ttl.Val(), Equals, 211915059) + c.Assert(ttl.Err(), IsNil) + c.Assert(ttl.Val(), Equals, 211915059) pttl := t.client.PTTL("key") - c.Check(pttl.Err(), IsNil) - c.Check(pttl.Val(), Equals, int64(211915059461)) + c.Assert(pttl.Err(), IsNil) + c.Assert(pttl.Val(), Equals, int64(211915059461)) } func (t *RedisTest) TestPTTL(c *C) { c.Skip("not implemented") set := t.client.Set("key", "Hello") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") expire := t.client.Expire("key", 1) - c.Check(expire.Err(), IsNil) - c.Check(set.Val(), Equals, true) + c.Assert(expire.Err(), IsNil) + c.Assert(set.Val(), Equals, true) pttl := t.client.PTTL("key") - c.Check(pttl.Err(), IsNil) - c.Check(pttl.Val(), Equals, int64(999)) + c.Assert(pttl.Err(), IsNil) + c.Assert(pttl.Val(), Equals, int64(999)) } func (t *RedisTest) TestRandomKey(c *C) { randomKey := t.client.RandomKey() - c.Check(randomKey.Err(), Equals, redis.Nil) - c.Check(randomKey.Val(), Equals, "") + c.Assert(randomKey.Err(), Equals, redis.Nil) + c.Assert(randomKey.Val(), Equals, "") set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") randomKey = t.client.RandomKey() - c.Check(randomKey.Err(), IsNil) - c.Check(randomKey.Val(), Equals, "foo") + c.Assert(randomKey.Err(), IsNil) + c.Assert(randomKey.Val(), Equals, "foo") } func (t *RedisTest) TestRename(c *C) { set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") status := t.client.Rename("foo", "foo1") - c.Check(status.Err(), IsNil) - c.Check(status.Val(), Equals, "OK") + c.Assert(status.Err(), IsNil) + c.Assert(status.Val(), Equals, "OK") get := t.client.Get("foo1") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "bar") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "bar") } func (t *RedisTest) TestRenameNX(c *C) { set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") renameNX := t.client.RenameNX("foo", "foo1") - c.Check(renameNX.Err(), IsNil) - c.Check(renameNX.Val(), Equals, true) + c.Assert(renameNX.Err(), IsNil) + c.Assert(renameNX.Val(), Equals, true) get := t.client.Get("foo1") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "bar") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "bar") } func (t *RedisTest) TestRestore(c *C) { @@ -348,126 +486,126 @@ func (t *RedisTest) TestSort(c *C) { func (t *RedisTest) TestTTL(c *C) { ttl := t.client.TTL("foo") - c.Check(ttl.Err(), IsNil) - c.Check(ttl.Val(), Equals, int64(-1)) + c.Assert(ttl.Err(), IsNil) + c.Assert(ttl.Val(), Equals, int64(-1)) set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") expire := t.client.Expire("foo", 60) - c.Check(expire.Err(), IsNil) - c.Check(expire.Val(), Equals, true) + c.Assert(expire.Err(), IsNil) + c.Assert(expire.Val(), Equals, true) ttl = t.client.TTL("foo") - c.Check(ttl.Err(), IsNil) - c.Check(ttl.Val(), Equals, int64(60)) + c.Assert(ttl.Err(), IsNil) + c.Assert(ttl.Val(), Equals, int64(60)) } func (t *RedisTest) Type(c *C) { set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") type_ := t.client.Type("foo") - c.Check(type_.Err(), IsNil) - c.Check(type_.Val(), Equals, "string") + c.Assert(type_.Err(), IsNil) + c.Assert(type_.Val(), Equals, "string") } // //------------------------------------------------------------------------------ func (t *RedisTest) TestAppend(c *C) { append := t.client.Append("foo", "bar") - c.Check(append.Err(), IsNil) - c.Check(append.Val(), Equals, int64(3)) + c.Assert(append.Err(), IsNil) + c.Assert(append.Val(), Equals, int64(3)) } func (t *RedisTest) TestDecr(c *C) { decr := t.client.Decr("foo") - c.Check(decr.Err(), IsNil) - c.Check(decr.Val(), Equals, int64(-1)) + c.Assert(decr.Err(), IsNil) + c.Assert(decr.Val(), Equals, int64(-1)) } func (t *RedisTest) TestDecrBy(c *C) { decrBy := t.client.DecrBy("foo", 10) - c.Check(decrBy.Err(), IsNil) - c.Check(decrBy.Val(), Equals, int64(-10)) + c.Assert(decrBy.Err(), IsNil) + c.Assert(decrBy.Val(), Equals, int64(-10)) } func (t *RedisTest) TestGet(c *C) { get := t.client.Get("foo") - c.Check(get.Err(), Equals, redis.Nil) - c.Check(get.Val(), Equals, "") + c.Assert(get.Err(), Equals, redis.Nil) + c.Assert(get.Val(), Equals, "") } func (t *RedisTest) TestSetGetBig(c *C) { getBit := t.client.GetBit("foo", 5) - c.Check(getBit.Err(), IsNil) - c.Check(getBit.Val(), Equals, int64(0)) + c.Assert(getBit.Err(), IsNil) + c.Assert(getBit.Val(), Equals, int64(0)) setBit := t.client.SetBit("foo", 5, 1) - c.Check(setBit.Err(), IsNil) - c.Check(setBit.Val(), Equals, int64(0)) + c.Assert(setBit.Err(), IsNil) + c.Assert(setBit.Val(), Equals, int64(0)) getBit = t.client.GetBit("foo", 5) - c.Check(getBit.Err(), IsNil) - c.Check(getBit.Val(), Equals, int64(1)) + c.Assert(getBit.Err(), IsNil) + c.Assert(getBit.Val(), Equals, int64(1)) } func (t *RedisTest) TestGetRange(c *C) { set := t.client.Set("foo", "hello") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") getRange := t.client.GetRange("foo", 0, 1) - c.Check(getRange.Err(), IsNil) - c.Check(getRange.Val(), Equals, "he") + c.Assert(getRange.Err(), IsNil) + c.Assert(getRange.Val(), Equals, "he") } func (t *RedisTest) TestGetSet(c *C) { set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") getSet := t.client.GetSet("foo", "bar2") - c.Check(getSet.Err(), IsNil) - c.Check(getSet.Val(), Equals, "bar") + c.Assert(getSet.Err(), IsNil) + c.Assert(getSet.Val(), Equals, "bar") get := t.client.Get("foo") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "bar2") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "bar2") } func (t *RedisTest) TestIncr(c *C) { incr := t.client.Incr("foo") - c.Check(incr.Err(), IsNil) - c.Check(incr.Val(), Equals, int64(1)) + c.Assert(incr.Err(), IsNil) + c.Assert(incr.Val(), Equals, int64(1)) } func (t *RedisTest) TestIncrBy(c *C) { incrBy := t.client.IncrBy("foo", 10) - c.Check(incrBy.Err(), IsNil) - c.Check(incrBy.Val(), Equals, int64(10)) + c.Assert(incrBy.Err(), IsNil) + c.Assert(incrBy.Val(), Equals, int64(10)) } func (t *RedisTest) TestMsetMget(c *C) { mSet := t.client.MSet("foo1", "bar1", "foo2", "bar2") - c.Check(mSet.Err(), IsNil) - c.Check(mSet.Val(), Equals, "OK") + c.Assert(mSet.Err(), IsNil) + c.Assert(mSet.Val(), Equals, "OK") mGet := t.client.MGet("foo1", "foo2") - c.Check(mGet.Err(), IsNil) - c.Check(mGet.Val(), DeepEquals, []interface{}{"bar1", "bar2"}) + c.Assert(mGet.Err(), IsNil) + c.Assert(mGet.Val(), DeepEquals, []interface{}{"bar1", "bar2"}) } func (t *RedisTest) MSetNX(c *C) { mSetNX := t.client.MSetNX("foo1", "bar1", "foo2", "bar2") - c.Check(mSetNX.Err(), IsNil) - c.Check(mSetNX.Val(), Equals, true) + c.Assert(mSetNX.Err(), IsNil) + c.Assert(mSetNX.Val(), Equals, true) mSetNX = t.client.MSetNX("foo1", "bar1", "foo2", "bar2") - c.Check(mSetNX.Err(), IsNil) - c.Check(mSetNX.Val(), Equals, false) + c.Assert(mSetNX.Err(), IsNil) + c.Assert(mSetNX.Val(), Equals, false) } func (t *RedisTest) PSetEx(c *C) { @@ -476,133 +614,133 @@ func (t *RedisTest) PSetEx(c *C) { func (t *RedisTest) TestSetGet(c *C) { set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") get := t.client.Get("foo") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "bar") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "bar") } func (t *RedisTest) TestSetEx(c *C) { setEx := t.client.SetEx("foo", 10, "bar") - c.Check(setEx.Err(), IsNil) - c.Check(setEx.Val(), Equals, "OK") + c.Assert(setEx.Err(), IsNil) + c.Assert(setEx.Val(), Equals, "OK") ttl := t.client.TTL("foo") - c.Check(ttl.Err(), IsNil) - c.Check(ttl.Val(), Equals, int64(10)) + c.Assert(ttl.Err(), IsNil) + c.Assert(ttl.Val(), Equals, int64(10)) } func (t *RedisTest) TestSetNX(c *C) { setNX := t.client.SetNX("foo", "bar") - c.Check(setNX.Err(), IsNil) - c.Check(setNX.Val(), Equals, true) + c.Assert(setNX.Err(), IsNil) + c.Assert(setNX.Val(), Equals, true) setNX = t.client.SetNX("foo", "bar2") - c.Check(setNX.Err(), IsNil) - c.Check(setNX.Val(), Equals, false) + c.Assert(setNX.Err(), IsNil) + c.Assert(setNX.Val(), Equals, false) get := t.client.Get("foo") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "bar") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "bar") } func (t *RedisTest) TestSetRange(c *C) { set := t.client.Set("foo", "Hello World") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") range_ := t.client.SetRange("foo", 6, "Redis") - c.Check(range_.Err(), IsNil) - c.Check(range_.Val(), Equals, int64(11)) + c.Assert(range_.Err(), IsNil) + c.Assert(range_.Val(), Equals, int64(11)) get := t.client.Get("foo") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "Hello Redis") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "Hello Redis") } func (t *RedisTest) TestStrLen(c *C) { set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") strLen := t.client.StrLen("foo") - c.Check(strLen.Err(), IsNil) - c.Check(strLen.Val(), Equals, int64(3)) + c.Assert(strLen.Err(), IsNil) + c.Assert(strLen.Val(), Equals, int64(3)) strLen = t.client.StrLen("_") - c.Check(strLen.Err(), IsNil) - c.Check(strLen.Val(), Equals, int64(0)) + c.Assert(strLen.Err(), IsNil) + c.Assert(strLen.Val(), Equals, int64(0)) } //------------------------------------------------------------------------------ func (t *RedisTest) TestHDel(c *C) { hSet := t.client.HSet("myhash", "foo", "bar") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hDel := t.client.HDel("myhash", "foo") - c.Check(hDel.Err(), IsNil) - c.Check(hDel.Val(), Equals, int64(1)) + c.Assert(hDel.Err(), IsNil) + c.Assert(hDel.Val(), Equals, int64(1)) hDel = t.client.HDel("myhash", "foo") - c.Check(hDel.Err(), IsNil) - c.Check(hDel.Val(), Equals, int64(0)) + c.Assert(hDel.Err(), IsNil) + c.Assert(hDel.Val(), Equals, int64(0)) } func (t *RedisTest) TestHExists(c *C) { hSet := t.client.HSet("myhash", "foo", "bar") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hExists := t.client.HExists("myhash", "foo") - c.Check(hExists.Err(), IsNil) - c.Check(hExists.Val(), Equals, true) + c.Assert(hExists.Err(), IsNil) + c.Assert(hExists.Val(), Equals, true) hExists = t.client.HExists("myhash", "foo1") - c.Check(hExists.Err(), IsNil) - c.Check(hExists.Val(), Equals, false) + c.Assert(hExists.Err(), IsNil) + c.Assert(hExists.Val(), Equals, false) } func (t *RedisTest) TestHGet(c *C) { hSet := t.client.HSet("myhash", "foo", "bar") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hGet := t.client.HGet("myhash", "foo") - c.Check(hGet.Err(), IsNil) - c.Check(hGet.Val(), Equals, "bar") + c.Assert(hGet.Err(), IsNil) + c.Assert(hGet.Val(), Equals, "bar") hGet = t.client.HGet("myhash", "foo1") - c.Check(hGet.Err(), Equals, redis.Nil) - c.Check(hGet.Val(), Equals, "") + c.Assert(hGet.Err(), Equals, redis.Nil) + c.Assert(hGet.Val(), Equals, "") } func (t *RedisTest) TestHGetAll(c *C) { hSet := t.client.HSet("myhash", "foo1", "bar1") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hSet = t.client.HSet("myhash", "foo2", "bar2") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hGetAll := t.client.HGetAll("myhash") - c.Check(hGetAll.Err(), IsNil) - c.Check(hGetAll.Val(), DeepEquals, []interface{}{"foo1", "bar1", "foo2", "bar2"}) + c.Assert(hGetAll.Err(), IsNil) + c.Assert(hGetAll.Val(), DeepEquals, []interface{}{"foo1", "bar1", "foo2", "bar2"}) } func (t *RedisTest) TestHIncrBy(c *C) { hSet := t.client.HSet("myhash", "foo", "5") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hIncrBy := t.client.HIncrBy("myhash", "foo", 1) - c.Check(hIncrBy.Err(), IsNil) - c.Check(hIncrBy.Val(), Equals, int64(6)) + c.Assert(hIncrBy.Err(), IsNil) + c.Assert(hIncrBy.Val(), Equals, int64(6)) hIncrBy = t.client.HIncrBy("myhash", "foo", -1) - c.Check(hIncrBy.Err(), IsNil) - c.Check(hIncrBy.Val(), Equals, int64(5)) + c.Assert(hIncrBy.Err(), IsNil) + c.Assert(hIncrBy.Val(), Equals, int64(5)) hIncrBy = t.client.HIncrBy("myhash", "foo", -10) - c.Check(hIncrBy.Err(), IsNil) - c.Check(hIncrBy.Val(), Equals, int64(-5)) + c.Assert(hIncrBy.Err(), IsNil) + c.Assert(hIncrBy.Val(), Equals, int64(-5)) } func (t *RedisTest) TestHIncrByFloat(c *C) { @@ -611,95 +749,95 @@ func (t *RedisTest) TestHIncrByFloat(c *C) { func (t *RedisTest) TestHKeys(c *C) { hSet := t.client.HSet("myhash", "foo1", "bar1") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hSet = t.client.HSet("myhash", "foo2", "bar2") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hKeys := t.client.HKeys("myhash") - c.Check(hKeys.Err(), IsNil) - c.Check(hKeys.Val(), DeepEquals, []interface{}{"foo1", "foo2"}) + c.Assert(hKeys.Err(), IsNil) + c.Assert(hKeys.Val(), DeepEquals, []interface{}{"foo1", "foo2"}) } func (t *RedisTest) TestHLen(c *C) { hSet := t.client.HSet("myhash", "foo1", "bar1") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hSet = t.client.HSet("myhash", "foo2", "bar2") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hLen := t.client.HLen("myhash") - c.Check(hLen.Err(), IsNil) - c.Check(hLen.Val(), Equals, int64(2)) + c.Assert(hLen.Err(), IsNil) + c.Assert(hLen.Val(), Equals, int64(2)) } func (t *RedisTest) TestHMGet(c *C) { hSet := t.client.HSet("myhash", "foo1", "bar1") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hSet = t.client.HSet("myhash", "foo2", "bar2") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hMGet := t.client.HMGet("myhash", "foo1", "foo2", "_") - c.Check(hMGet.Err(), IsNil) - c.Check(hMGet.Val(), DeepEquals, []interface{}{"bar1", "bar2", nil}) + c.Assert(hMGet.Err(), IsNil) + c.Assert(hMGet.Val(), DeepEquals, []interface{}{"bar1", "bar2", nil}) } func (t *RedisTest) TestHMSet(c *C) { hMSet := t.client.HMSet("myhash", "foo1", "bar1", "foo2", "bar2") - c.Check(hMSet.Err(), IsNil) - c.Check(hMSet.Val(), Equals, "OK") + c.Assert(hMSet.Err(), IsNil) + c.Assert(hMSet.Val(), Equals, "OK") hGet := t.client.HGet("myhash", "foo1") - c.Check(hGet.Err(), IsNil) - c.Check(hGet.Val(), Equals, "bar1") + c.Assert(hGet.Err(), IsNil) + c.Assert(hGet.Val(), Equals, "bar1") hGet = t.client.HGet("myhash", "foo2") - c.Check(hGet.Err(), IsNil) - c.Check(hGet.Val(), Equals, "bar2") + c.Assert(hGet.Err(), IsNil) + c.Assert(hGet.Val(), Equals, "bar2") } func (t *RedisTest) TestHSet(c *C) { hSet := t.client.HSet("myhash", "foo", "bar") - c.Check(hSet.Err(), IsNil) - c.Check(hSet.Val(), Equals, true) + c.Assert(hSet.Err(), IsNil) + c.Assert(hSet.Val(), Equals, true) hGet := t.client.HGet("myhash", "foo") - c.Check(hGet.Err(), IsNil) - c.Check(hGet.Val(), Equals, "bar") + c.Assert(hGet.Err(), IsNil) + c.Assert(hGet.Val(), Equals, "bar") } func (t *RedisTest) TestHSetNX(c *C) { hSetNX := t.client.HSetNX("myhash", "foo", "bar") - c.Check(hSetNX.Err(), IsNil) - c.Check(hSetNX.Val(), Equals, true) + c.Assert(hSetNX.Err(), IsNil) + c.Assert(hSetNX.Val(), Equals, true) hSetNX = t.client.HSetNX("myhash", "foo", "bar") - c.Check(hSetNX.Err(), IsNil) - c.Check(hSetNX.Val(), Equals, false) + c.Assert(hSetNX.Err(), IsNil) + c.Assert(hSetNX.Val(), Equals, false) hGet := t.client.HGet("myhash", "foo") - c.Check(hGet.Err(), IsNil) - c.Check(hGet.Val(), Equals, "bar") + c.Assert(hGet.Err(), IsNil) + c.Assert(hGet.Val(), Equals, "bar") } func (t *RedisTest) TestHVals(c *C) { hSet := t.client.HSet("myhash", "foo1", "bar1") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hSet = t.client.HSet("myhash", "foo2", "bar2") - c.Check(hSet.Err(), IsNil) + c.Assert(hSet.Err(), IsNil) hVals := t.client.HVals("myhash") - c.Check(hVals.Err(), IsNil) - c.Check(hVals.Val(), DeepEquals, []interface{}{"bar1", "bar2"}) + c.Assert(hVals.Err(), IsNil) + c.Assert(hVals.Val(), DeepEquals, []interface{}{"bar1", "bar2"}) } //------------------------------------------------------------------------------ func (t *RedisTest) TestBLPop(c *C) { rPush := t.client.RPush("list1", "a", "b", "c") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) bLPop := t.client.BLPop(0, "list1", "list2") - c.Check(bLPop.Err(), IsNil) - c.Check(bLPop.Val(), DeepEquals, []interface{}{"list1", "a"}) + c.Assert(bLPop.Err(), IsNil) + c.Assert(bLPop.Val(), DeepEquals, []interface{}{"list1", "a"}) } func (t *RedisTest) TestBLPopBlocks(c *C) { @@ -708,8 +846,8 @@ func (t *RedisTest) TestBLPopBlocks(c *C) { go func() { started <- true bLPop := t.client.BLPop(0, "list") - c.Check(bLPop.Err(), IsNil) - c.Check(bLPop.Val(), DeepEquals, []interface{}{"list", "a"}) + c.Assert(bLPop.Err(), IsNil) + c.Assert(bLPop.Val(), DeepEquals, []interface{}{"list", "a"}) done <- true }() <-started @@ -722,7 +860,7 @@ func (t *RedisTest) TestBLPopBlocks(c *C) { } rPush := t.client.RPush("list", "a") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) select { case <-done: @@ -735,11 +873,11 @@ func (t *RedisTest) TestBLPopBlocks(c *C) { func (t *RedisTest) TestBRPop(c *C) { rPush := t.client.RPush("list1", "a", "b", "c") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) bRPop := t.client.BRPop(0, "list1", "list2") - c.Check(bRPop.Err(), IsNil) - c.Check(bRPop.Val(), DeepEquals, []interface{}{"list1", "c"}) + c.Assert(bRPop.Err(), IsNil) + c.Assert(bRPop.Val(), DeepEquals, []interface{}{"list1", "c"}) } func (t *RedisTest) TestBRPopBlocks(c *C) { @@ -748,8 +886,8 @@ func (t *RedisTest) TestBRPopBlocks(c *C) { go func() { started <- true bRPop := t.client.BRPop(0, "list") - c.Check(bRPop.Err(), IsNil) - c.Check(bRPop.Val(), DeepEquals, []interface{}{"list", "a"}) + c.Assert(bRPop.Err(), IsNil) + c.Assert(bRPop.Val(), DeepEquals, []interface{}{"list", "a"}) done <- true }() <-started @@ -762,7 +900,7 @@ func (t *RedisTest) TestBRPopBlocks(c *C) { } rPush := t.client.RPush("list", "a") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) select { case <-done: @@ -775,609 +913,609 @@ func (t *RedisTest) TestBRPopBlocks(c *C) { func (t *RedisTest) TestBRPopLPush(c *C) { rPush := t.client.RPush("list1", "a", "b", "c") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) bRPopLPush := t.client.BRPopLPush("list1", "list2", 0) - c.Check(bRPopLPush.Err(), IsNil) - c.Check(bRPopLPush.Val(), Equals, "c") + c.Assert(bRPopLPush.Err(), IsNil) + c.Assert(bRPopLPush.Val(), Equals, "c") } func (t *RedisTest) TestLIndex(c *C) { lPush := t.client.LPush("list", "World") - c.Check(lPush.Err(), IsNil) + c.Assert(lPush.Err(), IsNil) lPush = t.client.LPush("list", "Hello") - c.Check(lPush.Err(), IsNil) + c.Assert(lPush.Err(), IsNil) lIndex := t.client.LIndex("list", 0) - c.Check(lIndex.Err(), IsNil) - c.Check(lIndex.Val(), Equals, "Hello") + c.Assert(lIndex.Err(), IsNil) + c.Assert(lIndex.Val(), Equals, "Hello") lIndex = t.client.LIndex("list", -1) - c.Check(lIndex.Err(), IsNil) - c.Check(lIndex.Val(), Equals, "World") + c.Assert(lIndex.Err(), IsNil) + c.Assert(lIndex.Val(), Equals, "World") lIndex = t.client.LIndex("list", 3) - c.Check(lIndex.Err(), Equals, redis.Nil) - c.Check(lIndex.Val(), Equals, "") + c.Assert(lIndex.Err(), Equals, redis.Nil) + c.Assert(lIndex.Val(), Equals, "") } func (t *RedisTest) TestLInsert(c *C) { rPush := t.client.RPush("list", "Hello") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "World") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) lInsert := t.client.LInsert("list", "BEFORE", "World", "There") - c.Check(lInsert.Err(), IsNil) - c.Check(lInsert.Val(), Equals, int64(3)) + c.Assert(lInsert.Err(), IsNil) + c.Assert(lInsert.Val(), Equals, int64(3)) lRange := t.client.LRange("list", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"Hello", "There", "World"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"Hello", "There", "World"}) } func (t *RedisTest) TestLLen(c *C) { lPush := t.client.LPush("list", "World") - c.Check(lPush.Err(), IsNil) + c.Assert(lPush.Err(), IsNil) lPush = t.client.LPush("list", "Hello") - c.Check(lPush.Err(), IsNil) + c.Assert(lPush.Err(), IsNil) lLen := t.client.LLen("list") - c.Check(lLen.Err(), IsNil) - c.Check(lLen.Val(), Equals, int64(2)) + c.Assert(lLen.Err(), IsNil) + c.Assert(lLen.Val(), Equals, int64(2)) } func (t *RedisTest) TestLPop(c *C) { rPush := t.client.RPush("list", "one") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "two") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "three") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) lPop := t.client.LPop("list") - c.Check(lPop.Err(), IsNil) - c.Check(lPop.Val(), Equals, "one") + c.Assert(lPop.Err(), IsNil) + c.Assert(lPop.Val(), Equals, "one") lRange := t.client.LRange("list", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"two", "three"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"two", "three"}) } func (t *RedisTest) TestLPush(c *C) { lPush := t.client.LPush("list", "World") - c.Check(lPush.Err(), IsNil) + c.Assert(lPush.Err(), IsNil) lPush = t.client.LPush("list", "Hello") - c.Check(lPush.Err(), IsNil) + c.Assert(lPush.Err(), IsNil) lRange := t.client.LRange("list", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"Hello", "World"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"Hello", "World"}) } func (t *RedisTest) TestLPushX(c *C) { lPush := t.client.LPush("list", "World") - c.Check(lPush.Err(), IsNil) + c.Assert(lPush.Err(), IsNil) lPushX := t.client.LPushX("list", "Hello") - c.Check(lPushX.Err(), IsNil) - c.Check(lPushX.Val(), Equals, int64(2)) + c.Assert(lPushX.Err(), IsNil) + c.Assert(lPushX.Val(), Equals, int64(2)) lPushX = t.client.LPushX("list2", "Hello") - c.Check(lPushX.Err(), IsNil) - c.Check(lPushX.Val(), Equals, int64(0)) + c.Assert(lPushX.Err(), IsNil) + c.Assert(lPushX.Val(), Equals, int64(0)) lRange := t.client.LRange("list", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"Hello", "World"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"Hello", "World"}) lRange = t.client.LRange("list2", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{}) } func (t *RedisTest) TestLRange(c *C) { rPush := t.client.RPush("list", "one") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "two") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "three") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) lRange := t.client.LRange("list", 0, 0) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"one"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"one"}) lRange = t.client.LRange("list", -3, 2) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"one", "two", "three"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"one", "two", "three"}) lRange = t.client.LRange("list", -100, 100) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"one", "two", "three"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"one", "two", "three"}) lRange = t.client.LRange("list", 5, 10) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{}) } func (t *RedisTest) TestLRem(c *C) { rPush := t.client.RPush("list", "hello") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "hello") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "foo") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "hello") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) lRem := t.client.LRem("list", -2, "hello") - c.Check(lRem.Err(), IsNil) - c.Check(lRem.Val(), Equals, int64(2)) + c.Assert(lRem.Err(), IsNil) + c.Assert(lRem.Val(), Equals, int64(2)) lRange := t.client.LRange("list", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"hello", "foo"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"hello", "foo"}) } func (t *RedisTest) TestLSet(c *C) { rPush := t.client.RPush("list", "one") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "two") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "three") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) lSet := t.client.LSet("list", 0, "four") - c.Check(lSet.Err(), IsNil) - c.Check(lSet.Val(), Equals, "OK") + c.Assert(lSet.Err(), IsNil) + c.Assert(lSet.Val(), Equals, "OK") lSet = t.client.LSet("list", -2, "five") - c.Check(lSet.Err(), IsNil) - c.Check(lSet.Val(), Equals, "OK") + c.Assert(lSet.Err(), IsNil) + c.Assert(lSet.Val(), Equals, "OK") lRange := t.client.LRange("list", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"four", "five", "three"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"four", "five", "three"}) } func (t *RedisTest) TestLTrim(c *C) { rPush := t.client.RPush("list", "one") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "two") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "three") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) lTrim := t.client.LTrim("list", 1, -1) - c.Check(lTrim.Err(), IsNil) - c.Check(lTrim.Val(), Equals, "OK") + c.Assert(lTrim.Err(), IsNil) + c.Assert(lTrim.Val(), Equals, "OK") lRange := t.client.LRange("list", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"two", "three"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"two", "three"}) } func (t *RedisTest) TestRPop(c *C) { rPush := t.client.RPush("list", "one") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "two") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "three") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPop := t.client.RPop("list") - c.Check(rPop.Err(), IsNil) - c.Check(rPop.Val(), Equals, "three") + c.Assert(rPop.Err(), IsNil) + c.Assert(rPop.Val(), Equals, "three") lRange := t.client.LRange("list", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"one", "two"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"one", "two"}) } func (t *RedisTest) TestRPopLPush(c *C) { rPush := t.client.RPush("list", "one") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "two") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPush = t.client.RPush("list", "three") - c.Check(rPush.Err(), IsNil) + c.Assert(rPush.Err(), IsNil) rPopLPush := t.client.RPopLPush("list", "list2") - c.Check(rPopLPush.Err(), IsNil) - c.Check(rPopLPush.Val(), Equals, "three") + c.Assert(rPopLPush.Err(), IsNil) + c.Assert(rPopLPush.Val(), Equals, "three") lRange := t.client.LRange("list", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"one", "two"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"one", "two"}) lRange = t.client.LRange("list2", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"three"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"three"}) } func (t *RedisTest) TestRPush(c *C) { rPush := t.client.RPush("list", "Hello") - c.Check(rPush.Err(), IsNil) - c.Check(rPush.Val(), Equals, int64(1)) + c.Assert(rPush.Err(), IsNil) + c.Assert(rPush.Val(), Equals, int64(1)) rPush = t.client.RPush("list", "World") - c.Check(rPush.Err(), IsNil) - c.Check(rPush.Val(), Equals, int64(2)) + c.Assert(rPush.Err(), IsNil) + c.Assert(rPush.Val(), Equals, int64(2)) lRange := t.client.LRange("list", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"Hello", "World"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"Hello", "World"}) } func (t *RedisTest) TestRPushX(c *C) { rPush := t.client.RPush("list", "Hello") - c.Check(rPush.Err(), IsNil) - c.Check(rPush.Val(), Equals, int64(1)) + c.Assert(rPush.Err(), IsNil) + c.Assert(rPush.Val(), Equals, int64(1)) rPushX := t.client.RPushX("list", "World") - c.Check(rPushX.Err(), IsNil) - c.Check(rPushX.Val(), Equals, int64(2)) + c.Assert(rPushX.Err(), IsNil) + c.Assert(rPushX.Val(), Equals, int64(2)) rPushX = t.client.RPushX("list2", "World") - c.Check(rPushX.Err(), IsNil) - c.Check(rPushX.Val(), Equals, int64(0)) + c.Assert(rPushX.Err(), IsNil) + c.Assert(rPushX.Val(), Equals, int64(0)) lRange := t.client.LRange("list", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{"Hello", "World"}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{"Hello", "World"}) lRange = t.client.LRange("list2", 0, -1) - c.Check(lRange.Err(), IsNil) - c.Check(lRange.Val(), DeepEquals, []interface{}{}) + c.Assert(lRange.Err(), IsNil) + c.Assert(lRange.Val(), DeepEquals, []interface{}{}) } //------------------------------------------------------------------------------ func (t *RedisTest) TestSAdd(c *C) { sAdd := t.client.SAdd("set", "Hello") - c.Check(sAdd.Err(), IsNil) - c.Check(sAdd.Val(), Equals, int64(1)) + c.Assert(sAdd.Err(), IsNil) + c.Assert(sAdd.Val(), Equals, int64(1)) sAdd = t.client.SAdd("set", "World") - c.Check(sAdd.Err(), IsNil) - c.Check(sAdd.Val(), Equals, int64(1)) + c.Assert(sAdd.Err(), IsNil) + c.Assert(sAdd.Val(), Equals, int64(1)) sAdd = t.client.SAdd("set", "World") - c.Check(sAdd.Err(), IsNil) - c.Check(sAdd.Val(), Equals, int64(0)) + c.Assert(sAdd.Err(), IsNil) + c.Assert(sAdd.Val(), Equals, int64(0)) sMembers := t.client.SMembers("set") - c.Check(sMembers.Err(), IsNil) - c.Check(sMembers.Val(), DeepEquals, []interface{}{"World", "Hello"}) + c.Assert(sMembers.Err(), IsNil) + c.Assert(sMembers.Val(), DeepEquals, []interface{}{"World", "Hello"}) } func (t *RedisTest) TestSCard(c *C) { sAdd := t.client.SAdd("set", "Hello") - c.Check(sAdd.Err(), IsNil) - c.Check(sAdd.Val(), Equals, int64(1)) + c.Assert(sAdd.Err(), IsNil) + c.Assert(sAdd.Val(), Equals, int64(1)) sAdd = t.client.SAdd("set", "World") - c.Check(sAdd.Err(), IsNil) - c.Check(sAdd.Val(), Equals, int64(1)) + c.Assert(sAdd.Err(), IsNil) + c.Assert(sAdd.Val(), Equals, int64(1)) sCard := t.client.SCard("set") - c.Check(sCard.Err(), IsNil) - c.Check(sCard.Val(), Equals, int64(2)) + c.Assert(sCard.Err(), IsNil) + c.Assert(sCard.Val(), Equals, int64(2)) } func (t *RedisTest) TestSDiff(c *C) { sAdd := t.client.SAdd("set1", "a") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "b") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "d") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "e") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sDiff := t.client.SDiff("set1", "set2") - c.Check(sDiff.Err(), IsNil) - c.Check(sDiff.Val(), DeepEquals, []interface{}{"a", "b"}) + c.Assert(sDiff.Err(), IsNil) + c.Assert(sDiff.Val(), DeepEquals, []interface{}{"a", "b"}) } func (t *RedisTest) TestSDiffStore(c *C) { sAdd := t.client.SAdd("set1", "a") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "b") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "d") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "e") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sDiffStore := t.client.SDiffStore("set", "set1", "set2") - c.Check(sDiffStore.Err(), IsNil) - c.Check(sDiffStore.Val(), Equals, int64(2)) + c.Assert(sDiffStore.Err(), IsNil) + c.Assert(sDiffStore.Val(), Equals, int64(2)) sMembers := t.client.SMembers("set") - c.Check(sMembers.Err(), IsNil) - c.Check(sMembers.Val(), DeepEquals, []interface{}{"a", "b"}) + c.Assert(sMembers.Err(), IsNil) + c.Assert(sMembers.Val(), DeepEquals, []interface{}{"a", "b"}) } func (t *RedisTest) TestSInter(c *C) { sAdd := t.client.SAdd("set1", "a") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "b") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "d") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "e") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sInter := t.client.SInter("set1", "set2") - c.Check(sInter.Err(), IsNil) - c.Check(sInter.Val(), DeepEquals, []interface{}{"c"}) + c.Assert(sInter.Err(), IsNil) + c.Assert(sInter.Val(), DeepEquals, []interface{}{"c"}) } func (t *RedisTest) TestSInterStore(c *C) { sAdd := t.client.SAdd("set1", "a") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "b") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "d") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "e") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sInterStore := t.client.SInterStore("set", "set1", "set2") - c.Check(sInterStore.Err(), IsNil) - c.Check(sInterStore.Val(), Equals, int64(1)) + c.Assert(sInterStore.Err(), IsNil) + c.Assert(sInterStore.Val(), Equals, int64(1)) sMembers := t.client.SMembers("set") - c.Check(sMembers.Err(), IsNil) - c.Check(sMembers.Val(), DeepEquals, []interface{}{"c"}) + c.Assert(sMembers.Err(), IsNil) + c.Assert(sMembers.Val(), DeepEquals, []interface{}{"c"}) } func (t *RedisTest) TestIsMember(c *C) { sAdd := t.client.SAdd("set", "one") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sIsMember := t.client.SIsMember("set", "one") - c.Check(sIsMember.Err(), IsNil) - c.Check(sIsMember.Val(), Equals, true) + c.Assert(sIsMember.Err(), IsNil) + c.Assert(sIsMember.Val(), Equals, true) sIsMember = t.client.SIsMember("set", "two") - c.Check(sIsMember.Err(), IsNil) - c.Check(sIsMember.Val(), Equals, false) + c.Assert(sIsMember.Err(), IsNil) + c.Assert(sIsMember.Val(), Equals, false) } func (t *RedisTest) TestSMembers(c *C) { sAdd := t.client.SAdd("set", "Hello") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set", "World") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sMembers := t.client.SMembers("set") - c.Check(sMembers.Err(), IsNil) - c.Check(sMembers.Val(), DeepEquals, []interface{}{"World", "Hello"}) + c.Assert(sMembers.Err(), IsNil) + c.Assert(sMembers.Val(), DeepEquals, []interface{}{"World", "Hello"}) } func (t *RedisTest) TestSMove(c *C) { sAdd := t.client.SAdd("set1", "one") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "two") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "three") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sMove := t.client.SMove("set1", "set2", "two") - c.Check(sMove.Err(), IsNil) - c.Check(sMove.Val(), Equals, true) + c.Assert(sMove.Err(), IsNil) + c.Assert(sMove.Val(), Equals, true) sMembers := t.client.SMembers("set1") - c.Check(sMembers.Err(), IsNil) - c.Check(sMembers.Val(), DeepEquals, []interface{}{"one"}) + c.Assert(sMembers.Err(), IsNil) + c.Assert(sMembers.Val(), DeepEquals, []interface{}{"one"}) sMembers = t.client.SMembers("set2") - c.Check(sMembers.Err(), IsNil) - c.Check(sMembers.Val(), DeepEquals, []interface{}{"three", "two"}) + c.Assert(sMembers.Err(), IsNil) + c.Assert(sMembers.Val(), DeepEquals, []interface{}{"three", "two"}) } func (t *RedisTest) TestSPop(c *C) { sAdd := t.client.SAdd("set", "one") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set", "two") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set", "three") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sPop := t.client.SPop("set") - c.Check(sPop.Err(), IsNil) - c.Check(sPop.Val(), Not(Equals), "") + c.Assert(sPop.Err(), IsNil) + c.Assert(sPop.Val(), Not(Equals), "") sMembers := t.client.SMembers("set") - c.Check(sMembers.Err(), IsNil) - c.Check(sMembers.Val(), HasLen, 2) + c.Assert(sMembers.Err(), IsNil) + c.Assert(sMembers.Val(), HasLen, 2) } func (t *RedisTest) TestSRandMember(c *C) { sAdd := t.client.SAdd("set", "one") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set", "two") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set", "three") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sRandMember := t.client.SRandMember("set") - c.Check(sRandMember.Err(), IsNil) - c.Check(sRandMember.Val(), Not(Equals), "") + c.Assert(sRandMember.Err(), IsNil) + c.Assert(sRandMember.Val(), Not(Equals), "") sMembers := t.client.SMembers("set") - c.Check(sMembers.Err(), IsNil) - c.Check(sMembers.Val(), HasLen, 3) + c.Assert(sMembers.Err(), IsNil) + c.Assert(sMembers.Val(), HasLen, 3) } func (t *RedisTest) TestSRem(c *C) { sAdd := t.client.SAdd("set", "one") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set", "two") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set", "three") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sRem := t.client.SRem("set", "one") - c.Check(sRem.Err(), IsNil) - c.Check(sRem.Val(), Equals, int64(1)) + c.Assert(sRem.Err(), IsNil) + c.Assert(sRem.Val(), Equals, int64(1)) sRem = t.client.SRem("set", "four") - c.Check(sRem.Err(), IsNil) - c.Check(sRem.Val(), Equals, int64(0)) + c.Assert(sRem.Err(), IsNil) + c.Assert(sRem.Val(), Equals, int64(0)) sMembers := t.client.SMembers("set") - c.Check(sMembers.Err(), IsNil) - c.Check(sMembers.Val(), DeepEquals, []interface{}{"three", "two"}) + c.Assert(sMembers.Err(), IsNil) + c.Assert(sMembers.Val(), DeepEquals, []interface{}{"three", "two"}) } func (t *RedisTest) TestSUnion(c *C) { sAdd := t.client.SAdd("set1", "a") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "b") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "d") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "e") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sUnion := t.client.SUnion("set1", "set2") - c.Check(sUnion.Err(), IsNil) - c.Check(sUnion.Val(), HasLen, 5) + c.Assert(sUnion.Err(), IsNil) + c.Assert(sUnion.Val(), HasLen, 5) } func (t *RedisTest) TestSUnionStore(c *C) { sAdd := t.client.SAdd("set1", "a") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "b") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set1", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "c") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "d") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sAdd = t.client.SAdd("set2", "e") - c.Check(sAdd.Err(), IsNil) + c.Assert(sAdd.Err(), IsNil) sUnionStore := t.client.SUnionStore("set", "set1", "set2") - c.Check(sUnionStore.Err(), IsNil) - c.Check(sUnionStore.Val(), Equals, int64(5)) + c.Assert(sUnionStore.Err(), IsNil) + c.Assert(sUnionStore.Val(), Equals, int64(5)) sMembers := t.client.SMembers("set") - c.Check(sMembers.Err(), IsNil) - c.Check(sMembers.Val(), HasLen, 5) + c.Assert(sMembers.Err(), IsNil) + c.Assert(sMembers.Val(), HasLen, 5) } //------------------------------------------------------------------------------ func (t *RedisTest) TestZAdd(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) - c.Check(zAdd.Val(), Equals, int64(1)) + c.Assert(zAdd.Err(), IsNil) + c.Assert(zAdd.Val(), Equals, int64(1)) zAdd = t.client.ZAdd("zset", redis.NewZMember(1, "uno")) - c.Check(zAdd.Err(), IsNil) - c.Check(zAdd.Val(), Equals, int64(1)) + c.Assert(zAdd.Err(), IsNil) + c.Assert(zAdd.Val(), Equals, int64(1)) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) - c.Check(zAdd.Val(), Equals, int64(1)) + c.Assert(zAdd.Err(), IsNil) + c.Assert(zAdd.Val(), Equals, int64(1)) zAdd = t.client.ZAdd("zset", redis.NewZMember(3, "two")) - c.Check(zAdd.Err(), IsNil) - c.Check(zAdd.Val(), Equals, int64(0)) + c.Assert(zAdd.Err(), IsNil) + c.Assert(zAdd.Val(), Equals, int64(0)) zRange := t.client.ZRange("zset", 0, -1, true) - c.Check(zRange.Err(), IsNil) - c.Check(zRange.Val(), DeepEquals, []interface{}{"one", "1", "uno", "1", "two", "3"}) + c.Assert(zRange.Err(), IsNil) + c.Assert(zRange.Val(), DeepEquals, []interface{}{"one", "1", "uno", "1", "two", "3"}) } func (t *RedisTest) TestZCard(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zCard := t.client.ZCard("zset") - c.Check(zCard.Err(), IsNil) - c.Check(zCard.Val(), Equals, int64(2)) + c.Assert(zCard.Err(), IsNil) + c.Assert(zCard.Val(), Equals, int64(2)) } func (t *RedisTest) TestZCount(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(3, "three")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zCount := t.client.ZCount("zset", "-inf", "+inf") - c.Check(zCount.Err(), IsNil) - c.Check(zCount.Val(), Equals, int64(3)) + c.Assert(zCount.Err(), IsNil) + c.Assert(zCount.Val(), Equals, int64(3)) zCount = t.client.ZCount("zset", "(1", "3") - c.Check(zCount.Err(), IsNil) - c.Check(zCount.Val(), Equals, int64(2)) + c.Assert(zCount.Err(), IsNil) + c.Assert(zCount.Val(), Equals, int64(2)) } func (t *RedisTest) TestZIncrBy(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zIncrBy := t.client.ZIncrBy("zset", 2, "one") - c.Check(zIncrBy.Err(), IsNil) - c.Check(zIncrBy.Val(), Equals, float64(3)) + c.Assert(zIncrBy.Err(), IsNil) + c.Assert(zIncrBy.Val(), Equals, float64(3)) zRange := t.client.ZRange("zset", 0, -1, true) - c.Check(zRange.Err(), IsNil) - c.Check(zRange.Val(), DeepEquals, []interface{}{"two", "2", "one", "3"}) + c.Assert(zRange.Err(), IsNil) + c.Assert(zRange.Val(), DeepEquals, []interface{}{"two", "2", "one", "3"}) } func (t *RedisTest) TestZInterStore(c *C) { zAdd := t.client.ZAdd("zset1", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset1", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset2", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset2", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset3", redis.NewZMember(3, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zInterStore := t.client.ZInterStore( "out", @@ -1386,208 +1524,208 @@ func (t *RedisTest) TestZInterStore(c *C) { []int64{2, 3}, "", ) - c.Check(zInterStore.Err(), IsNil) - c.Check(zInterStore.Val(), Equals, int64(2)) + c.Assert(zInterStore.Err(), IsNil) + c.Assert(zInterStore.Val(), Equals, int64(2)) zRange := t.client.ZRange("out", 0, -1, true) - c.Check(zRange.Err(), IsNil) - c.Check(zRange.Val(), DeepEquals, []interface{}{"one", "5", "two", "10"}) + c.Assert(zRange.Err(), IsNil) + c.Assert(zRange.Val(), DeepEquals, []interface{}{"one", "5", "two", "10"}) } func (t *RedisTest) TestZRange(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(3, "three")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zRange := t.client.ZRange("zset", 0, -1, false) - c.Check(zRange.Err(), IsNil) - c.Check(zRange.Val(), DeepEquals, []interface{}{"one", "two", "three"}) + c.Assert(zRange.Err(), IsNil) + c.Assert(zRange.Val(), DeepEquals, []interface{}{"one", "two", "three"}) zRange = t.client.ZRange("zset", 2, 3, false) - c.Check(zRange.Err(), IsNil) - c.Check(zRange.Val(), DeepEquals, []interface{}{"three"}) + c.Assert(zRange.Err(), IsNil) + c.Assert(zRange.Val(), DeepEquals, []interface{}{"three"}) zRange = t.client.ZRange("zset", -2, -1, false) - c.Check(zRange.Err(), IsNil) - c.Check(zRange.Val(), DeepEquals, []interface{}{"two", "three"}) + c.Assert(zRange.Err(), IsNil) + c.Assert(zRange.Val(), DeepEquals, []interface{}{"two", "three"}) } func (t *RedisTest) TestZRangeByScore(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(3, "three")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zRangeByScore := t.client.ZRangeByScore("zset", "-inf", "+inf", false, nil) - c.Check(zRangeByScore.Err(), IsNil) - c.Check(zRangeByScore.Val(), DeepEquals, []interface{}{"one", "two", "three"}) + c.Assert(zRangeByScore.Err(), IsNil) + c.Assert(zRangeByScore.Val(), DeepEquals, []interface{}{"one", "two", "three"}) zRangeByScore = t.client.ZRangeByScore("zset", "1", "2", false, nil) - c.Check(zRangeByScore.Err(), IsNil) - c.Check(zRangeByScore.Val(), DeepEquals, []interface{}{"one", "two"}) + c.Assert(zRangeByScore.Err(), IsNil) + c.Assert(zRangeByScore.Val(), DeepEquals, []interface{}{"one", "two"}) zRangeByScore = t.client.ZRangeByScore("zset", "(1", "2", false, nil) - c.Check(zRangeByScore.Err(), IsNil) - c.Check(zRangeByScore.Val(), DeepEquals, []interface{}{"two"}) + c.Assert(zRangeByScore.Err(), IsNil) + c.Assert(zRangeByScore.Val(), DeepEquals, []interface{}{"two"}) zRangeByScore = t.client.ZRangeByScore("zset", "(1", "(2", false, nil) - c.Check(zRangeByScore.Err(), IsNil) - c.Check(zRangeByScore.Val(), DeepEquals, []interface{}{}) + c.Assert(zRangeByScore.Err(), IsNil) + c.Assert(zRangeByScore.Val(), DeepEquals, []interface{}{}) } func (t *RedisTest) TestZRank(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(3, "three")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zRank := t.client.ZRank("zset", "three") - c.Check(zRank.Err(), IsNil) - c.Check(zRank.Val(), Equals, int64(2)) + c.Assert(zRank.Err(), IsNil) + c.Assert(zRank.Val(), Equals, int64(2)) zRank = t.client.ZRank("zset", "four") - c.Check(zRank.Err(), Equals, redis.Nil) - c.Check(zRank.Val(), Equals, int64(0)) + c.Assert(zRank.Err(), Equals, redis.Nil) + c.Assert(zRank.Val(), Equals, int64(0)) } func (t *RedisTest) TestZRem(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(3, "three")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zRem := t.client.ZRem("zset", "two") - c.Check(zRem.Err(), IsNil) - c.Check(zRem.Val(), Equals, int64(1)) + c.Assert(zRem.Err(), IsNil) + c.Assert(zRem.Val(), Equals, int64(1)) zRange := t.client.ZRange("zset", 0, -1, true) - c.Check(zRange.Err(), IsNil) - c.Check(zRange.Val(), DeepEquals, []interface{}{"one", "1", "three", "3"}) + c.Assert(zRange.Err(), IsNil) + c.Assert(zRange.Val(), DeepEquals, []interface{}{"one", "1", "three", "3"}) } func (t *RedisTest) TestZRemRangeByRank(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(3, "three")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zRemRangeByRank := t.client.ZRemRangeByRank("zset", 0, 1) - c.Check(zRemRangeByRank.Err(), IsNil) - c.Check(zRemRangeByRank.Val(), Equals, int64(2)) + c.Assert(zRemRangeByRank.Err(), IsNil) + c.Assert(zRemRangeByRank.Val(), Equals, int64(2)) zRange := t.client.ZRange("zset", 0, -1, true) - c.Check(zRange.Err(), IsNil) - c.Check(zRange.Val(), DeepEquals, []interface{}{"three", "3"}) + c.Assert(zRange.Err(), IsNil) + c.Assert(zRange.Val(), DeepEquals, []interface{}{"three", "3"}) } func (t *RedisTest) TestZRemRangeByScore(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(3, "three")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zRemRangeByScore := t.client.ZRemRangeByScore("zset", "-inf", "(2") - c.Check(zRemRangeByScore.Err(), IsNil) - c.Check(zRemRangeByScore.Val(), Equals, int64(1)) + c.Assert(zRemRangeByScore.Err(), IsNil) + c.Assert(zRemRangeByScore.Val(), Equals, int64(1)) zRange := t.client.ZRange("zset", 0, -1, true) - c.Check(zRange.Err(), IsNil) - c.Check(zRange.Val(), DeepEquals, []interface{}{"two", "2", "three", "3"}) + c.Assert(zRange.Err(), IsNil) + c.Assert(zRange.Val(), DeepEquals, []interface{}{"two", "2", "three", "3"}) } func (t *RedisTest) TestZRevRange(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(3, "three")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zRevRange := t.client.ZRevRange("zset", "0", "-1", false) - c.Check(zRevRange.Err(), IsNil) - c.Check(zRevRange.Val(), DeepEquals, []interface{}{"three", "two", "one"}) + c.Assert(zRevRange.Err(), IsNil) + c.Assert(zRevRange.Val(), DeepEquals, []interface{}{"three", "two", "one"}) zRevRange = t.client.ZRevRange("zset", "2", "3", false) - c.Check(zRevRange.Err(), IsNil) - c.Check(zRevRange.Val(), DeepEquals, []interface{}{"one"}) + c.Assert(zRevRange.Err(), IsNil) + c.Assert(zRevRange.Val(), DeepEquals, []interface{}{"one"}) zRevRange = t.client.ZRevRange("zset", "-2", "-1", false) - c.Check(zRevRange.Err(), IsNil) - c.Check(zRevRange.Val(), DeepEquals, []interface{}{"two", "one"}) + c.Assert(zRevRange.Err(), IsNil) + c.Assert(zRevRange.Val(), DeepEquals, []interface{}{"two", "one"}) } func (t *RedisTest) TestZRevRangeByScore(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(3, "three")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zRevRangeByScore := t.client.ZRevRangeByScore("zset", "+inf", "-inf", false, nil) - c.Check(zRevRangeByScore.Err(), IsNil) - c.Check(zRevRangeByScore.Val(), DeepEquals, []interface{}{"three", "two", "one"}) + c.Assert(zRevRangeByScore.Err(), IsNil) + c.Assert(zRevRangeByScore.Val(), DeepEquals, []interface{}{"three", "two", "one"}) zRevRangeByScore = t.client.ZRevRangeByScore("zset", "2", "(1", false, nil) - c.Check(zRevRangeByScore.Err(), IsNil) - c.Check(zRevRangeByScore.Val(), DeepEquals, []interface{}{"two"}) + c.Assert(zRevRangeByScore.Err(), IsNil) + c.Assert(zRevRangeByScore.Val(), DeepEquals, []interface{}{"two"}) zRevRangeByScore = t.client.ZRevRangeByScore("zset", "(2", "(1", false, nil) - c.Check(zRevRangeByScore.Err(), IsNil) - c.Check(zRevRangeByScore.Val(), DeepEquals, []interface{}{}) + c.Assert(zRevRangeByScore.Err(), IsNil) + c.Assert(zRevRangeByScore.Val(), DeepEquals, []interface{}{}) } func (t *RedisTest) TestZRevRank(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset", redis.NewZMember(3, "three")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zRevRank := t.client.ZRevRank("zset", "one") - c.Check(zRevRank.Err(), IsNil) - c.Check(zRevRank.Val(), Equals, int64(2)) + c.Assert(zRevRank.Err(), IsNil) + c.Assert(zRevRank.Val(), Equals, int64(2)) zRevRank = t.client.ZRevRank("zset", "four") - c.Check(zRevRank.Err(), Equals, redis.Nil) - c.Check(zRevRank.Val(), Equals, int64(0)) + c.Assert(zRevRank.Err(), Equals, redis.Nil) + c.Assert(zRevRank.Val(), Equals, int64(0)) } func (t *RedisTest) TestZScore(c *C) { zAdd := t.client.ZAdd("zset", redis.NewZMember(1.001, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zScore := t.client.ZScore("zset", "one") - c.Check(zScore.Err(), IsNil) - c.Check(zScore.Val(), Equals, float64(1.001)) + c.Assert(zScore.Err(), IsNil) + c.Assert(zScore.Val(), Equals, float64(1.001)) } func (t *RedisTest) TestZUnionStore(c *C) { zAdd := t.client.ZAdd("zset1", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset1", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset2", redis.NewZMember(1, "one")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset2", redis.NewZMember(2, "two")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zAdd = t.client.ZAdd("zset2", redis.NewZMember(3, "three")) - c.Check(zAdd.Err(), IsNil) + c.Assert(zAdd.Err(), IsNil) zUnionStore := t.client.ZUnionStore( "out", @@ -1596,59 +1734,61 @@ func (t *RedisTest) TestZUnionStore(c *C) { []int64{2, 3}, "", ) - c.Check(zUnionStore.Err(), IsNil) - c.Check(zUnionStore.Val(), Equals, int64(3)) + c.Assert(zUnionStore.Err(), IsNil) + c.Assert(zUnionStore.Val(), Equals, int64(3)) zRange := t.client.ZRange("out", 0, -1, true) - c.Check(zRange.Err(), IsNil) - c.Check(zRange.Val(), DeepEquals, []interface{}{"one", "5", "three", "9", "two", "10"}) + c.Assert(zRange.Err(), IsNil) + c.Assert(zRange.Val(), DeepEquals, []interface{}{"one", "5", "three", "9", "two", "10"}) } //------------------------------------------------------------------------------ func (t *RedisTest) TestPatternPubSub(c *C) { pubsub, err := t.client.PubSubClient() - c.Check(err, IsNil) - defer pubsub.Close() + c.Assert(err, IsNil) + defer func() { + c.Assert(pubsub.Close(), IsNil) + }() ch, err := pubsub.PSubscribe("mychannel*") - c.Check(err, IsNil) - c.Check(ch, Not(IsNil)) + c.Assert(err, IsNil) + c.Assert(ch, Not(IsNil)) pub := t.client.Publish("mychannel1", "hello") - c.Check(pub.Err(), IsNil) - c.Check(pub.Val(), Equals, int64(1)) + c.Assert(pub.Err(), IsNil) + c.Assert(pub.Val(), Equals, int64(1)) err = pubsub.PUnsubscribe("mychannel*") - c.Check(err, IsNil) + c.Assert(err, IsNil) select { case msg := <-ch: - c.Check(msg.Err, Equals, nil) - c.Check(msg.Name, Equals, "psubscribe") - c.Check(msg.Channel, Equals, "mychannel*") - c.Check(msg.Number, Equals, int64(1)) + 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)) case <-time.After(time.Second): c.Error("Channel is empty.") } select { case msg := <-ch: - c.Check(msg.Err, Equals, nil) - c.Check(msg.Name, Equals, "pmessage") - c.Check(msg.ChannelPattern, Equals, "mychannel*") - c.Check(msg.Channel, Equals, "mychannel1") - c.Check(msg.Message, Equals, "hello") + 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") case <-time.After(time.Second): c.Error("Channel is empty.") } select { case msg := <-ch: - c.Check(msg.Err, Equals, nil) - c.Check(msg.Name, Equals, "punsubscribe") - c.Check(msg.Channel, Equals, "mychannel*") - c.Check(msg.Number, Equals, int64(0)) + 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)) case <-time.After(time.Second): c.Error("Channel is empty.") } @@ -1656,87 +1796,89 @@ func (t *RedisTest) TestPatternPubSub(c *C) { func (t *RedisTest) TestPubSub(c *C) { pubsub, err := t.client.PubSubClient() - c.Check(err, IsNil) - defer pubsub.Close() + c.Assert(err, IsNil) + defer func() { + c.Assert(pubsub.Close(), IsNil) + }() ch, err := pubsub.Subscribe("mychannel") - c.Check(err, IsNil) - c.Check(ch, Not(IsNil)) + c.Assert(err, IsNil) + c.Assert(ch, Not(IsNil)) ch2, err := pubsub.Subscribe("mychannel2") - c.Check(err, IsNil) - c.Check(ch2, Equals, ch) + c.Assert(err, IsNil) + c.Assert(ch2, Equals, ch) pub := t.client.Publish("mychannel", "hello") - c.Check(pub.Err(), IsNil) - c.Check(pub.Val(), Equals, int64(1)) + c.Assert(pub.Err(), IsNil) + c.Assert(pub.Val(), Equals, int64(1)) pub = t.client.Publish("mychannel2", "hello2") - c.Check(pub.Err(), IsNil) - c.Check(pub.Val(), Equals, int64(1)) + c.Assert(pub.Err(), IsNil) + c.Assert(pub.Val(), Equals, int64(1)) err = pubsub.Unsubscribe("mychannel") - c.Check(err, IsNil) + c.Assert(err, IsNil) err = pubsub.Unsubscribe("mychannel2") - c.Check(err, IsNil) + c.Assert(err, IsNil) select { case msg := <-ch: - c.Check(msg.Err, Equals, nil) - c.Check(msg.Name, Equals, "subscribe") - c.Check(msg.Channel, Equals, "mychannel") - c.Check(msg.Number, Equals, int64(1)) + 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)) case <-time.After(time.Second): c.Error("Channel is empty.") } select { case msg := <-ch: - c.Check(msg.Err, Equals, nil) - c.Check(msg.Name, Equals, "subscribe") - c.Check(msg.Channel, Equals, "mychannel2") - c.Check(msg.Number, Equals, int64(2)) + 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)) case <-time.After(time.Second): c.Error("Channel is empty.") } select { case msg := <-ch: - c.Check(msg.Err, Equals, nil) - c.Check(msg.Name, Equals, "message") - c.Check(msg.Channel, Equals, "mychannel") - c.Check(msg.Message, Equals, "hello") + c.Assert(msg.Err, Equals, nil) + c.Assert(msg.Name, Equals, "message") + c.Assert(msg.Channel, Equals, "mychannel") + c.Assert(msg.Message, Equals, "hello") case <-time.After(time.Second): c.Error("Channel is empty.") } select { case msg := <-ch: - c.Check(msg.Err, Equals, nil) - c.Check(msg.Name, Equals, "message") - c.Check(msg.Channel, Equals, "mychannel2") - c.Check(msg.Message, Equals, "hello2") + c.Assert(msg.Err, Equals, nil) + c.Assert(msg.Name, Equals, "message") + c.Assert(msg.Channel, Equals, "mychannel2") + c.Assert(msg.Message, Equals, "hello2") case <-time.After(time.Second): c.Error("Channel is empty.") } select { case msg := <-ch: - c.Check(msg.Err, Equals, nil) - c.Check(msg.Name, Equals, "unsubscribe") - c.Check(msg.Channel, Equals, "mychannel") - c.Check(msg.Number, Equals, int64(1)) + 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)) case <-time.After(time.Second): c.Error("Channel is empty.") } select { case msg := <-ch: - c.Check(msg.Err, Equals, nil) - c.Check(msg.Name, Equals, "unsubscribe") - c.Check(msg.Channel, Equals, "mychannel2") - c.Check(msg.Number, Equals, int64(0)) + 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)) case <-time.After(time.Second): c.Error("Channel is empty.") } @@ -1746,52 +1888,61 @@ func (t *RedisTest) TestPubSub(c *C) { func (t *RedisTest) TestPipelining(c *C) { set := t.client.Set("foo2", "bar2") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") - multi, err := t.client.MultiClient() - c.Check(err, IsNil) + pipeline, err := t.client.PipelineClient() + c.Assert(err, IsNil) + defer func() { + c.Assert(pipeline.Close(), IsNil) + }() - multi.Multi() + setReq := pipeline.Set("foo1", "bar1") + getReq := pipeline.Get("foo2") - setReq := multi.Set("foo1", "bar1") - getReq := multi.Get("foo2") + reqs, err := pipeline.RunQueued() + c.Assert(err, IsNil) + c.Assert(reqs, HasLen, 2) - reqs, err := multi.RunQueued() - c.Check(err, IsNil) - c.Check(reqs, HasLen, 2) + c.Assert(setReq.Err(), IsNil) + c.Assert(setReq.Val(), Equals, "OK") - c.Check(setReq.Err(), IsNil) - c.Check(setReq.Val(), Equals, "OK") - - c.Check(getReq.Err(), IsNil) - c.Check(getReq.Val(), Equals, "bar2") + c.Assert(getReq.Err(), IsNil) + c.Assert(getReq.Val(), Equals, "bar2") } func (t *RedisTest) TestRunQueuedOnEmptyQueue(c *C) { - reqs, err := t.client.RunQueued() - c.Check(err, IsNil) - c.Check(reqs, HasLen, 0) + 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) } func (t *RedisTest) TestIncrPipeliningFromGoroutines(c *C) { - multi, err := t.client.PipelineClient() - c.Check(err, IsNil) - defer multi.Close() + pipeline, err := t.client.PipelineClient() + c.Assert(err, IsNil) + defer func() { + c.Assert(pipeline.Close(), IsNil) + }() wg := &sync.WaitGroup{} for i := int64(0); i < 20000; i++ { wg.Add(1) go func() { - multi.Incr("TestIncrPipeliningFromGoroutinesKey") + pipeline.Incr("TestIncrPipeliningFromGoroutinesKey") wg.Done() }() } wg.Wait() - reqs, err := multi.RunQueued() - c.Check(err, IsNil) - c.Check(reqs, HasLen, 20000) + reqs, err := pipeline.RunQueued() + c.Assert(err, IsNil) + c.Assert(reqs, HasLen, 20000) for _, req := range reqs { if req.Err() != nil { c.Errorf("got %v, expected nil", req.Err()) @@ -1799,41 +1950,51 @@ func (t *RedisTest) TestIncrPipeliningFromGoroutines(c *C) { } get := t.client.Get("TestIncrPipeliningFromGoroutinesKey") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "20000") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "20000") } func (t *RedisTest) TestPipeliningFromGoroutines(c *C) { - multi, err := t.client.PipelineClient() - c.Check(err, IsNil) - defer multi.Close() + pipeline, err := t.client.PipelineClient() + c.Assert(err, IsNil) + defer func() { + c.Assert(pipeline.Close(), IsNil) + }() + wg := &sync.WaitGroup{} for i := int64(0); i < 1000; i += 2 { + wg.Add(1) go func() { msg1 := "echo" + strconv.FormatInt(i, 10) msg2 := "echo" + strconv.FormatInt(i+1, 10) - echo1Req := multi.Echo(msg1) - echo2Req := multi.Echo(msg2) + echo1 := pipeline.Echo(msg1) + echo2 := pipeline.Echo(msg2) - reqs, err := multi.RunQueued() - c.Check(reqs, HasLen, 2) - c.Check(err, IsNil) + reqs, err := pipeline.RunQueued() + c.Assert(err, IsNil) + c.Assert(reqs, HasLen, 2) - c.Check(echo1Req.Err(), IsNil) - c.Check(echo1Req.Val(), Equals, msg1) + c.Assert(echo1.Err(), IsNil) + c.Assert(echo1.Val(), Equals, msg1) - c.Check(echo2Req.Err(), IsNil) - c.Check(echo2Req.Val(), Equals, msg2) + c.Assert(echo2.Err(), IsNil) + c.Assert(echo2.Val(), Equals, msg2) + + wg.Done() }() } + wg.Wait() } //------------------------------------------------------------------------------ -func (t *RedisTest) TestDiscard(c *C) { +func (t *RedisTest) TestMultiDiscard(c *C) { multi, err := t.client.MultiClient() - c.Check(err, IsNil) + c.Assert(err, IsNil) + defer func() { + c.Assert(multi.Close(), IsNil) + }() multi.Multi() @@ -1842,21 +2003,24 @@ func (t *RedisTest) TestDiscard(c *C) { multi.Set("foo2", "bar2") reqs, err := multi.Exec() - c.Check(err, IsNil) - c.Check(reqs, HasLen, 1) + c.Assert(err, IsNil) + c.Assert(reqs, HasLen, 1) get := t.client.Get("foo1") - c.Check(get.Err(), Equals, redis.Nil) - c.Check(get.Val(), Equals, "") + c.Assert(get.Err(), Equals, redis.Nil) + c.Assert(get.Val(), Equals, "") get = t.client.Get("foo2") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "bar2") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "bar2") } func (t *RedisTest) TestMultiExec(c *C) { multi, err := t.client.MultiClient() - c.Check(err, IsNil) + c.Assert(err, IsNil) + defer func() { + c.Assert(multi.Close(), IsNil) + }() multi.Multi() @@ -1864,33 +2028,43 @@ func (t *RedisTest) TestMultiExec(c *C) { getR := multi.Get("foo") reqs, err := multi.Exec() - c.Check(err, IsNil) - c.Check(reqs, HasLen, 2) + c.Assert(err, IsNil) + c.Assert(reqs, HasLen, 2) - c.Check(setR.Err(), IsNil) - c.Check(setR.Val(), Equals, "OK") + c.Assert(setR.Err(), IsNil) + c.Assert(setR.Val(), Equals, "OK") - c.Check(getR.Err(), IsNil) - c.Check(getR.Val(), Equals, "bar") + c.Assert(getR.Err(), IsNil) + c.Assert(getR.Val(), Equals, "bar") } -func (t *RedisTest) TestExecOnEmptyQueue(c *C) { - reqs, err := t.client.Exec() - c.Check(err, IsNil) - c.Check(reqs, HasLen, 0) +func (t *RedisTest) TestMultiExecOnEmptyQueue(c *C) { + multi, err := t.client.MultiClient() + c.Assert(err, IsNil) + defer func() { + c.Check(multi.Close(), IsNil) + }() + + reqs, err := multi.Exec() + c.Assert(err, IsNil) + c.Assert(reqs, HasLen, 0) } //------------------------------------------------------------------------------ func (t *RedisTest) TestEchoFromGoroutines(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.Check(echo.Err(), IsNil) - c.Check(echo.Val(), Equals, msg) + c.Assert(echo.Err(), IsNil) + c.Assert(echo.Val(), Equals, msg) + wg.Done() }() } + wg.Wait() } func (t *RedisTest) TestIncrFromGoroutines(c *C) { @@ -1899,20 +2073,23 @@ func (t *RedisTest) TestIncrFromGoroutines(c *C) { wg.Add(1) go func() { incr := t.client.Incr("TestIncrFromGoroutinesKey") - c.Check(incr.Err(), IsNil) + c.Assert(incr.Err(), IsNil) wg.Done() }() } wg.Wait() get := t.client.Get("TestIncrFromGoroutinesKey") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "20000") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "20000") } func (t *RedisTest) TestIncrTransaction(c *C) { multi, err := t.client.MultiClient() - c.Check(err, IsNil) + c.Assert(err, IsNil) + defer func() { + c.Assert(multi.Close(), IsNil) + }() multi.Multi() @@ -1927,8 +2104,8 @@ func (t *RedisTest) TestIncrTransaction(c *C) { wg.Wait() reqs, err := multi.Exec() - c.Check(err, IsNil) - c.Check(reqs, HasLen, 20000) + c.Assert(err, IsNil) + c.Assert(reqs, HasLen, 20000) for _, req := range reqs { if req.Err() != nil { c.Errorf("got %v, expected nil", req.Err()) @@ -1936,25 +2113,27 @@ func (t *RedisTest) TestIncrTransaction(c *C) { } get := t.client.Get("TestIncrTransactionKey") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "20000") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "20000") } func (t *RedisTest) transactionalIncr(c *C, wg *sync.WaitGroup) { multi, err := t.client.MultiClient() - c.Check(err, IsNil) - defer multi.Close() + c.Assert(err, IsNil) + defer func() { + c.Assert(multi.Close(), IsNil) + }() watch := multi.Watch("foo") - c.Check(watch.Err(), IsNil) - c.Check(watch.Val(), Equals, "OK") + c.Assert(watch.Err(), IsNil) + c.Assert(watch.Val(), Equals, "OK") get := multi.Get("foo") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Not(Equals), redis.Nil) + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Not(Equals), redis.Nil) v, err := strconv.ParseInt(get.Val(), 10, 64) - c.Check(err, IsNil) + c.Assert(err, IsNil) multi.Multi() set := multi.Set("foo", strconv.FormatInt(v+1, 10)) @@ -1963,19 +2142,19 @@ func (t *RedisTest) transactionalIncr(c *C, wg *sync.WaitGroup) { t.transactionalIncr(c, wg) return } - c.Check(reqs, HasLen, 1) - c.Check(err, IsNil) + c.Assert(reqs, HasLen, 1) + c.Assert(err, IsNil) - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") wg.Done() } func (t *RedisTest) TestWatchUnwatch(c *C) { set := t.client.Set("foo", "0") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") wg := &sync.WaitGroup{} for i := 0; i < 1000; i++ { @@ -1985,8 +2164,8 @@ func (t *RedisTest) TestWatchUnwatch(c *C) { wg.Wait() get := t.client.Get("foo") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "1000") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "1000") } //------------------------------------------------------------------------------ @@ -1996,8 +2175,8 @@ func (t *RedisTest) BenchmarkRedisPing(c *C) { for i := 0; i < 10; i++ { ping := t.client.Ping() - c.Check(ping.Err(), IsNil) - c.Check(ping.Val(), Equals, "PONG") + c.Assert(ping.Err(), IsNil) + c.Assert(ping.Val(), Equals, "PONG") } c.StartTimer() @@ -2012,8 +2191,8 @@ func (t *RedisTest) BenchmarkRedisSet(c *C) { for i := 0; i < 10; i++ { set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) - c.Check(set.Val(), Equals, "OK") + c.Assert(set.Err(), IsNil) + c.Assert(set.Val(), Equals, "OK") } c.StartTimer() @@ -2028,8 +2207,8 @@ func (t *RedisTest) BenchmarkRedisGetNil(c *C) { for i := 0; i < 10; i++ { get := t.client.Get("foo") - c.Check(get.Err(), Equals, redis.Nil) - c.Check(get.Val(), Equals, "") + c.Assert(get.Err(), Equals, redis.Nil) + c.Assert(get.Val(), Equals, "") } c.StartTimer() @@ -2043,12 +2222,12 @@ func (t *RedisTest) BenchmarkRedisGet(c *C) { c.StopTimer() set := t.client.Set("foo", "bar") - c.Check(set.Err(), IsNil) + c.Assert(set.Err(), IsNil) for i := 0; i < 10; i++ { get := t.client.Get("foo") - c.Check(get.Err(), IsNil) - c.Check(get.Val(), Equals, "bar") + c.Assert(get.Err(), IsNil) + c.Assert(get.Val(), Equals, "bar") } c.StartTimer() @@ -2062,12 +2241,12 @@ func (t *RedisTest) BenchmarkRedisMGet(c *C) { c.StopTimer() mSet := t.client.MSet("foo1", "bar1", "foo2", "bar2") - c.Check(mSet.Err(), IsNil) + c.Assert(mSet.Err(), IsNil) for i := 0; i < 10; i++ { mGet := t.client.MGet("foo1", "foo2") - c.Check(mGet.Err(), IsNil) - c.Check(mGet.Val(), DeepEquals, []interface{}{"bar1", "bar2"}) + c.Assert(mGet.Err(), IsNil) + c.Assert(mGet.Val(), DeepEquals, []interface{}{"bar1", "bar2"}) } c.StartTimer() @@ -2081,15 +2260,15 @@ func (t *RedisTest) BenchmarkRedisWriteRead(c *C) { c.StopTimer() conn, _, err := t.client.ConnPool.Get() - c.Check(err, IsNil) + c.Assert(err, IsNil) for i := 0; i < 10; i++ { err := t.client.WriteReq([]byte("PING\r\n"), conn) - c.Check(err, IsNil) + c.Assert(err, IsNil) line, _, err := conn.Rd.ReadLine() - c.Check(err, IsNil) - c.Check(line, DeepEquals, []byte("+PONG")) + c.Assert(err, IsNil) + c.Assert(line, DeepEquals, []byte("+PONG")) } c.StartTimer()