2014-05-16 11:03:23 +04:00
|
|
|
package server
|
2014-05-08 06:54:33 +04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-06-22 06:39:23 +04:00
|
|
|
"github.com/siddontang/ledisdb/client/go/ledis"
|
2014-05-08 06:54:33 +04:00
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestZSet(t *testing.T) {
|
|
|
|
c := getTestConn()
|
|
|
|
defer c.Close()
|
|
|
|
|
|
|
|
key := []byte("myzset")
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zadd", key, 3, "a", 4, "b")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcard", key)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(n)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zadd", key, 1, "a", 2, "b")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 0 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcard", key)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(n)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zadd", key, 3, "c", 4, "d")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcard", key)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 4 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if s, err := ledis.Int(c.Do("zscore", key, "c")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if s != 3 {
|
|
|
|
t.Fatal(s)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zrem", key, "d", "e")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 1 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcard", key)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 3 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zincrby", key, 4, "c")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 7 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zincrby", key, -4, "c")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 3 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zincrby", key, 4, "d")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 4 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcard", key)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 4 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zrem", key, "a", "b", "c", "d")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 4 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcard", key)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 0 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestZSetCount(t *testing.T) {
|
|
|
|
c := getTestConn()
|
|
|
|
defer c.Close()
|
|
|
|
|
|
|
|
key := []byte("myzset")
|
2014-06-22 06:39:23 +04:00
|
|
|
if _, err := ledis.Int(c.Do("zadd", key, 1, "a", 2, "b", 3, "c", 4, "d")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcount", key, 2, 4)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 3 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcount", key, 4, 4)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 1 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcount", key, 4, 3)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 0 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcount", key, "(2", 4)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcount", key, "2", "(4")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcount", key, "(2", "(4")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 1 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcount", key, "-inf", "+inf")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 4 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Do("zadd", key, 3, "e")
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcount", key, "(2", "(4")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Do("zrem", key, "a", "b", "c", "d", "e")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestZSetRank(t *testing.T) {
|
|
|
|
c := getTestConn()
|
|
|
|
defer c.Close()
|
|
|
|
|
|
|
|
key := []byte("myzset")
|
2014-06-22 06:39:23 +04:00
|
|
|
if _, err := ledis.Int(c.Do("zadd", key, 1, "a", 2, "b", 3, "c", 4, "d")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zrank", key, "c")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if _, err := ledis.Int(c.Do("zrank", key, "e")); err != ledis.ErrNil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zrevrank", key, "c")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 1 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if _, err := ledis.Int(c.Do("zrevrank", key, "e")); err != ledis.ErrNil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testZSetRange(ay []interface{}, checkValues ...interface{}) error {
|
|
|
|
if len(ay) != len(checkValues) {
|
|
|
|
return fmt.Errorf("invalid return number %d != %d", len(ay), len(checkValues))
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(ay); i++ {
|
|
|
|
v, ok := ay[i].([]byte)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid data %d %v %T", i, ay[i], ay[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
switch cv := checkValues[i].(type) {
|
|
|
|
case string:
|
|
|
|
if string(v) != cv {
|
|
|
|
return fmt.Errorf("not equal %s != %s", v, checkValues[i])
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
if s, _ := strconv.Atoi(string(v)); s != checkValues[i] {
|
|
|
|
return fmt.Errorf("not equal %s != %v", v, checkValues[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestZSetRangeScore(t *testing.T) {
|
|
|
|
c := getTestConn()
|
|
|
|
defer c.Close()
|
|
|
|
|
|
|
|
key := []byte("myzset_range")
|
2014-06-22 06:39:23 +04:00
|
|
|
if _, err := ledis.Int(c.Do("zadd", key, 1, "a", 2, "b", 3, "c", 4, "d")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrangebyscore", key, 1, 4, "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "a", 1, "b", 2, "c", 3, "d", 4); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrangebyscore", key, 1, 4, "withscores", "limit", 1, 2)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "b", 2, "c", 3); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrangebyscore", key, "-inf", "+inf", "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "a", 1, "b", 2, "c", 3, "d", 4); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrangebyscore", key, "(1", "(4")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "b", "c"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 03:55:34 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, 4, 1, "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "d", 4, "c", 3, "b", 2, "a", 1); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 03:55:34 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, 4, 1, "withscores", "limit", 1, 2)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "c", 3, "b", 2); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 03:55:34 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, "+inf", "-inf", "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "d", 4, "c", 3, "b", 2, "a", 1); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 03:55:34 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrevrangebyscore", key, "(4", "(1")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "c", "b"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zremrangebyscore", key, 2, 3)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcard", key)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrangebyscore", key, 1, 4)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "a", "d"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestZSetRange(t *testing.T) {
|
|
|
|
c := getTestConn()
|
|
|
|
defer c.Close()
|
|
|
|
|
|
|
|
key := []byte("myzset_range_rank")
|
2014-06-22 06:39:23 +04:00
|
|
|
if _, err := ledis.Int(c.Do("zadd", key, 1, "a", 2, "b", 3, "c", 4, "d")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrange", key, 0, 3, "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "a", 1, "b", 2, "c", 3, "d", 4); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrange", key, 1, 4, "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "b", 2, "c", 3, "d", 4); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrange", key, -2, -1, "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "c", 3, "d", 4); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrange", key, 0, -1, "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "a", 1, "b", 2, "c", 3, "d", 4); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrange", key, -1, -2, "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if len(v) != 0 {
|
|
|
|
t.Fatal(len(v))
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrevrange", key, 0, 4, "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "d", 4, "c", 3, "b", 2, "a", 1); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrevrange", key, 0, -1, "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "d", 4, "c", 3, "b", 2, "a", 1); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrevrange", key, 2, 3, "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "b", 2, "a", 1); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrevrange", key, -2, -1, "withscores")); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "b", 2, "a", 1); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zremrangebyrank", key, 2, 3)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcard", key)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if v, err := ledis.MultiBulk(c.Do("zrange", key, 0, 4)); err != nil {
|
2014-05-08 06:54:33 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
if err := testZSetRange(v, "a", "b"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2014-05-12 11:08:59 +04:00
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zclear", key)); err != nil {
|
2014-05-12 11:08:59 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 2 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-06-22 06:39:23 +04:00
|
|
|
if n, err := ledis.Int(c.Do("zcard", key)); err != nil {
|
2014-05-12 11:08:59 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if n != 0 {
|
|
|
|
t.Fatal(n)
|
|
|
|
}
|
|
|
|
|
2014-05-08 06:54:33 +04:00
|
|
|
}
|