chore: add more tests (#3954)

master^2
Kevin Wan 8 months ago committed by GitHub
parent 0ee44c7064
commit 8e97c5819f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2080,7 +2080,8 @@ func (s *Redis) Zaddnx(key string, score int64, value string) (val bool, err err
}
// ZaddnxCtx is the implementation of redis zadd nx command.
func (s *Redis) ZaddnxCtx(ctx context.Context, key string, score int64, value string) (val bool, err error) {
func (s *Redis) ZaddnxCtx(ctx context.Context, key string, score int64, value string) (
val bool, err error) {
return s.ZaddnxFloatCtx(ctx, key, float64(score), value)
}

@ -177,7 +177,7 @@ func TestRedis_NonBlock(t *testing.T) {
func TestRedis_Decr(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).Decr("a")
_, err := newRedis(client.Addr, badType()).Decr("a")
assert.NotNil(t, err)
val, err := client.Decr("a")
assert.Nil(t, err)
@ -190,7 +190,7 @@ func TestRedis_Decr(t *testing.T) {
func TestRedis_DecrBy(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).Decrby("a", 2)
_, err := newRedis(client.Addr, badType()).Decrby("a", 2)
assert.NotNil(t, err)
val, err := client.Decrby("a", 2)
assert.Nil(t, err)
@ -203,7 +203,7 @@ func TestRedis_DecrBy(t *testing.T) {
func TestRedis_Exists(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).Exists("a")
_, err := newRedis(client.Addr, badType()).Exists("a")
assert.NotNil(t, err)
ok, err := client.Exists("a")
assert.Nil(t, err)
@ -217,7 +217,7 @@ func TestRedis_Exists(t *testing.T) {
func TestRedisTLS_Exists(t *testing.T) {
runOnRedisTLS(t, func(client *Redis) {
_, err := New(client.Addr, badType()).Exists("a")
_, err := newRedis(client.Addr, badType()).Exists("a")
assert.NotNil(t, err)
ok, err := client.Exists("a")
assert.NotNil(t, err)
@ -232,7 +232,7 @@ func TestRedisTLS_Exists(t *testing.T) {
func TestRedis_ExistsMany(t *testing.T) {
runOnRedis(t, func(client *Redis) {
// Attempt to create a new Redis instance with an incorrect type and call ExistsMany
_, err := New(client.Addr, badType()).ExistsMany("key1", "key2")
_, err := newRedis(client.Addr, badType()).ExistsMany("key1", "key2")
assert.NotNil(t, err)
// Check if key1 and key2 exist, expecting that they do not
@ -261,7 +261,7 @@ func TestRedis_ExistsMany(t *testing.T) {
func TestRedis_Eval(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).Eval(`redis.call("EXISTS", KEYS[1])`, []string{"notexist"})
_, err := newRedis(client.Addr, badType()).Eval(`redis.call("EXISTS", KEYS[1])`, []string{"notexist"})
assert.NotNil(t, err)
_, err = client.Eval(`redis.call("EXISTS", KEYS[1])`, []string{"notexist"})
assert.Equal(t, Nil, err)
@ -279,7 +279,7 @@ func TestRedis_ScriptRun(t *testing.T) {
runOnRedis(t, func(client *Redis) {
sc := NewScript(`redis.call("EXISTS", KEYS[1])`)
sc2 := NewScript(`return redis.call("EXISTS", KEYS[1])`)
_, err := New(client.Addr, badType()).ScriptRun(sc, []string{"notexist"})
_, err := newRedis(client.Addr, badType()).ScriptRun(sc, []string{"notexist"})
assert.NotNil(t, err)
_, err = client.ScriptRun(sc, []string{"notexist"})
assert.Equal(t, Nil, err)
@ -297,7 +297,7 @@ func TestRedis_GeoHash(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := client.GeoHash("parent", "child1", "child2")
assert.Error(t, err)
_, err = New(client.Addr, badType()).GeoHash("parent", "child1", "child2")
_, err = newRedis(client.Addr, badType()).GeoHash("parent", "child1", "child2")
assert.Error(t, err)
})
}
@ -306,7 +306,7 @@ func TestRedis_Hgetall(t *testing.T) {
runOnRedis(t, func(client *Redis) {
assert.Nil(t, client.Hset("a", "aa", "aaa"))
assert.Nil(t, client.Hset("a", "bb", "bbb"))
_, err := New(client.Addr, badType()).Hgetall("a")
_, err := newRedis(client.Addr, badType()).Hgetall("a")
assert.NotNil(t, err)
vals, err := client.Hgetall("a")
assert.Nil(t, err)
@ -319,10 +319,10 @@ func TestRedis_Hgetall(t *testing.T) {
func TestRedis_Hvals(t *testing.T) {
runOnRedis(t, func(client *Redis) {
assert.NotNil(t, New(client.Addr, badType()).Hset("a", "aa", "aaa"))
assert.NotNil(t, newRedis(client.Addr, badType()).Hset("a", "aa", "aaa"))
assert.Nil(t, client.Hset("a", "aa", "aaa"))
assert.Nil(t, client.Hset("a", "bb", "bbb"))
_, err := New(client.Addr, badType()).Hvals("a")
_, err := newRedis(client.Addr, badType()).Hvals("a")
assert.NotNil(t, err)
vals, err := client.Hvals("a")
assert.Nil(t, err)
@ -334,7 +334,7 @@ func TestRedis_Hsetnx(t *testing.T) {
runOnRedis(t, func(client *Redis) {
assert.Nil(t, client.Hset("a", "aa", "aaa"))
assert.Nil(t, client.Hset("a", "bb", "bbb"))
_, err := New(client.Addr, badType()).Hsetnx("a", "bb", "ccc")
_, err := newRedis(client.Addr, badType()).Hsetnx("a", "bb", "ccc")
assert.NotNil(t, err)
ok, err := client.Hsetnx("a", "bb", "ccc")
assert.Nil(t, err)
@ -352,7 +352,7 @@ func TestRedis_HdelHlen(t *testing.T) {
runOnRedis(t, func(client *Redis) {
assert.Nil(t, client.Hset("a", "aa", "aaa"))
assert.Nil(t, client.Hset("a", "bb", "bbb"))
_, err := New(client.Addr, badType()).Hlen("a")
_, err := newRedis(client.Addr, badType()).Hlen("a")
assert.NotNil(t, err)
num, err := client.Hlen("a")
assert.Nil(t, err)
@ -368,7 +368,7 @@ func TestRedis_HdelHlen(t *testing.T) {
func TestRedis_HIncrBy(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).Hincrby("key", "field", 2)
_, err := newRedis(client.Addr, badType()).Hincrby("key", "field", 2)
assert.NotNil(t, err)
val, err := client.Hincrby("key", "field", 2)
assert.Nil(t, err)
@ -383,7 +383,7 @@ func TestRedis_Hkeys(t *testing.T) {
runOnRedis(t, func(client *Redis) {
assert.Nil(t, client.Hset("a", "aa", "aaa"))
assert.Nil(t, client.Hset("a", "bb", "bbb"))
_, err := New(client.Addr, badType()).Hkeys("a")
_, err := newRedis(client.Addr, badType()).Hkeys("a")
assert.NotNil(t, err)
vals, err := client.Hkeys("a")
assert.Nil(t, err)
@ -395,7 +395,7 @@ func TestRedis_Hmget(t *testing.T) {
runOnRedis(t, func(client *Redis) {
assert.Nil(t, client.Hset("a", "aa", "aaa"))
assert.Nil(t, client.Hset("a", "bb", "bbb"))
_, err := New(client.Addr, badType()).Hmget("a", "aa", "bb")
_, err := newRedis(client.Addr, badType()).Hmget("a", "aa", "bb")
assert.NotNil(t, err)
vals, err := client.Hmget("a", "aa", "bb")
assert.Nil(t, err)
@ -408,7 +408,7 @@ func TestRedis_Hmget(t *testing.T) {
func TestRedis_Hmset(t *testing.T) {
runOnRedis(t, func(client *Redis) {
assert.NotNil(t, New(client.Addr, badType()).Hmset("a", nil))
assert.NotNil(t, newRedis(client.Addr, badType()).Hmset("a", nil))
assert.Nil(t, client.Hmset("a", map[string]string{
"aa": "aaa",
"bb": "bbb",
@ -433,7 +433,7 @@ func TestRedis_Hscan(t *testing.T) {
var cursor uint64 = 0
sum := 0
for {
_, _, err := New(client.Addr, badType()).Hscan(key, cursor, "*", 100)
_, _, err := newRedis(client.Addr, badType()).Hscan(key, cursor, "*", 100)
assert.NotNil(t, err)
reMap, next, err := client.Hscan(key, cursor, "*", 100)
assert.Nil(t, err)
@ -445,7 +445,7 @@ func TestRedis_Hscan(t *testing.T) {
}
assert.Equal(t, sum, 3100)
_, err = New(client.Addr, badType()).Del(key)
_, err = newRedis(client.Addr, badType()).Del(key)
assert.Error(t, err)
_, err = client.Del(key)
assert.NoError(t, err)
@ -462,7 +462,7 @@ func TestRedis_Hscan(t *testing.T) {
func TestRedis_Incr(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).Incr("a")
_, err := newRedis(client.Addr, badType()).Incr("a")
assert.NotNil(t, err)
val, err := client.Incr("a")
assert.Nil(t, err)
@ -475,7 +475,7 @@ func TestRedis_Incr(t *testing.T) {
func TestRedis_IncrBy(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).Incrby("a", 2)
_, err := newRedis(client.Addr, badType()).Incrby("a", 2)
assert.NotNil(t, err)
val, err := client.Incrby("a", 2)
assert.Nil(t, err)
@ -492,7 +492,7 @@ func TestRedis_Keys(t *testing.T) {
assert.Nil(t, err)
err = client.Set("key2", "value2")
assert.Nil(t, err)
_, err = New(client.Addr, badType()).Keys("*")
_, err = newRedis(client.Addr, badType()).Keys("*")
assert.NotNil(t, err)
keys, err := client.Keys("*")
assert.Nil(t, err)
@ -504,13 +504,13 @@ func TestRedis_HyperLogLog(t *testing.T) {
t.Run("hyperloglog", func(t *testing.T) {
runOnRedis(t, func(client *Redis) {
client.Ping()
r := New(client.Addr)
_, err := New(client.Addr, badType()).Pfadd("key1", "val1")
r := newRedis(client.Addr)
_, err := newRedis(client.Addr, badType()).Pfadd("key1", "val1")
assert.Error(t, err)
ok, err := r.Pfadd("key1", "val1")
assert.Nil(t, err)
assert.True(t, ok)
_, err = New(client.Addr, badType()).Pfcount("key1")
_, err = newRedis(client.Addr, badType()).Pfcount("key1")
assert.Error(t, err)
val, err := r.Pfcount("key1")
assert.Nil(t, err)
@ -521,7 +521,7 @@ func TestRedis_HyperLogLog(t *testing.T) {
val, err = r.Pfcount("key2")
assert.Nil(t, err)
assert.Equal(t, int64(1), val)
err = New(client.Addr, badType()).Pfmerge("key3", "key1", "key2")
err = newRedis(client.Addr, badType()).Pfmerge("key3", "key1", "key2")
assert.Error(t, err)
err = r.Pfmerge("key1", "key2")
assert.Nil(t, err)
@ -542,22 +542,22 @@ func TestRedis_HyperLogLog(t *testing.T) {
func TestRedis_List(t *testing.T) {
t.Run("list", func(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).Lpush("key", "value1", "value2")
_, err := newRedis(client.Addr, badType()).Lpush("key", "value1", "value2")
assert.NotNil(t, err)
val, err := client.Lpush("key", "value1", "value2")
assert.Nil(t, err)
assert.Equal(t, 2, val)
_, err = New(client.Addr, badType()).Rpush("key", "value3", "value4")
_, err = newRedis(client.Addr, badType()).Rpush("key", "value3", "value4")
assert.NotNil(t, err)
val, err = client.Rpush("key", "value3", "value4")
assert.Nil(t, err)
assert.Equal(t, 4, val)
_, err = New(client.Addr, badType()).Llen("key")
_, err = newRedis(client.Addr, badType()).Llen("key")
assert.NotNil(t, err)
val, err = client.Llen("key")
assert.Nil(t, err)
assert.Equal(t, 4, val)
_, err = New(client.Addr, badType()).Lindex("key", 1)
_, err = newRedis(client.Addr, badType()).Lindex("key", 1)
assert.NotNil(t, err)
value, err := client.Lindex("key", 0)
assert.Nil(t, err)
@ -565,7 +565,7 @@ func TestRedis_List(t *testing.T) {
vals, err := client.Lrange("key", 0, 10)
assert.Nil(t, err)
assert.EqualValues(t, []string{"value2", "value1", "value3", "value4"}, vals)
_, err = New(client.Addr, badType()).Lpop("key")
_, err = newRedis(client.Addr, badType()).Lpop("key")
assert.NotNil(t, err)
v, err := client.Lpop("key")
assert.Nil(t, err)
@ -573,7 +573,7 @@ func TestRedis_List(t *testing.T) {
val, err = client.Lpush("key", "value1", "value2")
assert.Nil(t, err)
assert.Equal(t, 5, val)
_, err = New(client.Addr, badType()).Rpop("key")
_, err = newRedis(client.Addr, badType()).Rpop("key")
assert.NotNil(t, err)
v, err = client.Rpop("key")
assert.Nil(t, err)
@ -581,12 +581,12 @@ func TestRedis_List(t *testing.T) {
val, err = client.Rpush("key", "value4", "value3", "value3")
assert.Nil(t, err)
assert.Equal(t, 7, val)
_, err = New(client.Addr, badType()).Lrem("key", 2, "value1")
_, err = newRedis(client.Addr, badType()).Lrem("key", 2, "value1")
assert.NotNil(t, err)
n, err := client.Lrem("key", 2, "value1")
assert.Nil(t, err)
assert.Equal(t, 2, n)
_, err = New(client.Addr, badType()).Lrange("key", 0, 10)
_, err = newRedis(client.Addr, badType()).Lrange("key", 0, 10)
assert.NotNil(t, err)
vals, err = client.Lrange("key", 0, 10)
assert.Nil(t, err)
@ -597,7 +597,7 @@ func TestRedis_List(t *testing.T) {
vals, err = client.Lrange("key", 0, 10)
assert.Nil(t, err)
assert.EqualValues(t, []string{"value2", "value3", "value4"}, vals)
err = New(client.Addr, badType()).Ltrim("key", 0, 1)
err = newRedis(client.Addr, badType()).Ltrim("key", 0, 1)
assert.Error(t, err)
err = client.Ltrim("key", 0, 1)
assert.Nil(t, err)
@ -667,7 +667,7 @@ func TestRedis_Mget(t *testing.T) {
assert.Nil(t, err)
err = client.Set("key2", "value2")
assert.Nil(t, err)
_, err = New(client.Addr, badType()).Mget("key1", "key0", "key2", "key3")
_, err = newRedis(client.Addr, badType()).Mget("key1", "key0", "key2", "key3")
assert.NotNil(t, err)
vals, err := client.Mget("key1", "key0", "key2", "key3")
assert.Nil(t, err)
@ -686,7 +686,7 @@ func TestRedis_Mget(t *testing.T) {
func TestRedis_SetBit(t *testing.T) {
t.Run("setbit", func(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).SetBit("key", 1, 1)
_, err := newRedis(client.Addr, badType()).SetBit("key", 1, 1)
assert.Error(t, err)
val, err := client.SetBit("key", 1, 1)
if assert.NoError(t, err) {
@ -709,7 +709,7 @@ func TestRedis_GetBit(t *testing.T) {
val, err := client.SetBit("key", 2, 1)
assert.Nil(t, err)
assert.Equal(t, 0, val)
_, err = New(client.Addr, badType()).GetBit("key", 2)
_, err = newRedis(client.Addr, badType()).GetBit("key", 2)
assert.NotNil(t, err)
v, err := client.GetBit("key", 2)
assert.Nil(t, err)
@ -733,7 +733,7 @@ func TestRedis_BitCount(t *testing.T) {
assert.Equal(t, 0, val)
}
_, err := New(client.Addr, badType()).BitCount("key", 0, -1)
_, err := newRedis(client.Addr, badType()).BitCount("key", 0, -1)
assert.NotNil(t, err)
val, err := client.BitCount("key", 0, -1)
assert.Nil(t, err)
@ -763,7 +763,7 @@ func TestRedis_BitOpAnd(t *testing.T) {
assert.Nil(t, err)
err = client.Set("key2", "1")
assert.Nil(t, err)
_, err = New(client.Addr, badType()).BitOpAnd("destKey", "key1", "key2")
_, err = newRedis(client.Addr, badType()).BitOpAnd("destKey", "key1", "key2")
assert.NotNil(t, err)
val, err := client.BitOpAnd("destKey", "key1", "key2")
assert.Nil(t, err)
@ -779,7 +779,7 @@ func TestRedis_BitOpNot(t *testing.T) {
runOnRedis(t, func(client *Redis) {
err := client.Set("key1", "\u0000")
assert.Nil(t, err)
_, err = New(client.Addr, badType()).BitOpNot("destKey", "key1")
_, err = newRedis(client.Addr, badType()).BitOpNot("destKey", "key1")
assert.NotNil(t, err)
val, err := client.BitOpNot("destKey", "key1")
assert.Nil(t, err)
@ -796,7 +796,7 @@ func TestRedis_BitOpOr(t *testing.T) {
assert.Nil(t, err)
err = client.Set("key2", "0")
assert.Nil(t, err)
_, err = New(client.Addr, badType()).BitOpOr("destKey", "key1", "key2")
_, err = newRedis(client.Addr, badType()).BitOpOr("destKey", "key1", "key2")
assert.NotNil(t, err)
val, err := client.BitOpOr("destKey", "key1", "key2")
assert.Nil(t, err)
@ -813,7 +813,7 @@ func TestRedis_BitOpXor(t *testing.T) {
assert.Nil(t, err)
err = client.Set("key2", "\x0f")
assert.Nil(t, err)
_, err = New(client.Addr, badType()).BitOpXor("destKey", "key1", "key2")
_, err = newRedis(client.Addr, badType()).BitOpXor("destKey", "key1", "key2")
assert.NotNil(t, err)
val, err := client.BitOpXor("destKey", "key1", "key2")
assert.Nil(t, err)
@ -830,7 +830,7 @@ func TestRedis_BitPos(t *testing.T) {
err := client.Set("key", "\xff\xf0\x00")
assert.Nil(t, err)
_, err = New(client.Addr, badType()).BitPos("key", 0, 0, -1)
_, err = newRedis(client.Addr, badType()).BitPos("key", 0, 0, -1)
assert.NotNil(t, err)
val, err := client.BitPos("key", 0, 0, 2)
assert.Nil(t, err)
@ -856,7 +856,7 @@ func TestRedis_BitPos(t *testing.T) {
func TestRedis_Persist(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).Persist("key")
_, err := newRedis(client.Addr, badType()).Persist("key")
assert.NotNil(t, err)
ok, err := client.Persist("key")
assert.Nil(t, err)
@ -866,14 +866,14 @@ func TestRedis_Persist(t *testing.T) {
ok, err = client.Persist("key")
assert.Nil(t, err)
assert.False(t, ok)
err = New(client.Addr, badType()).Expire("key", 5)
err = newRedis(client.Addr, badType()).Expire("key", 5)
assert.NotNil(t, err)
err = client.Expire("key", 5)
assert.Nil(t, err)
ok, err = client.Persist("key")
assert.Nil(t, err)
assert.True(t, ok)
err = New(client.Addr, badType()).Expireat("key", time.Now().Unix()+5)
err = newRedis(client.Addr, badType()).Expireat("key", time.Now().Unix()+5)
assert.NotNil(t, err)
err = client.Expireat("key", time.Now().Unix()+5)
assert.Nil(t, err)
@ -896,7 +896,7 @@ func TestRedis_Scan(t *testing.T) {
assert.Nil(t, err)
err = client.Set("key2", "value2")
assert.Nil(t, err)
_, _, err = New(client.Addr, badType()).Scan(0, "*", 100)
_, _, err = newRedis(client.Addr, badType()).Scan(0, "*", 100)
assert.NotNil(t, err)
keys, _, err := client.Scan(0, "*", 100)
assert.Nil(t, err)
@ -918,7 +918,7 @@ func TestRedis_Sscan(t *testing.T) {
var cursor uint64 = 0
sum := 0
for {
_, _, err := New(client.Addr, badType()).Sscan(key, cursor, "", 100)
_, _, err := newRedis(client.Addr, badType()).Sscan(key, cursor, "", 100)
assert.NotNil(t, err)
keys, next, err := client.Sscan(key, cursor, "", 100)
assert.Nil(t, err)
@ -930,7 +930,7 @@ func TestRedis_Sscan(t *testing.T) {
}
assert.Equal(t, sum, 1550)
_, err = New(client.Addr, badType()).Del(key)
_, err = newRedis(client.Addr, badType()).Del(key)
assert.NotNil(t, err)
_, err = client.Del(key)
assert.Nil(t, err)
@ -940,48 +940,48 @@ func TestRedis_Sscan(t *testing.T) {
func TestRedis_Set(t *testing.T) {
t.Run("set", func(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).Sadd("key", 1, 2, 3, 4)
_, err := newRedis(client.Addr, badType()).Sadd("key", 1, 2, 3, 4)
assert.NotNil(t, err)
num, err := client.Sadd("key", 1, 2, 3, 4)
assert.Nil(t, err)
assert.Equal(t, 4, num)
_, err = New(client.Addr, badType()).Scard("key")
_, err = newRedis(client.Addr, badType()).Scard("key")
assert.NotNil(t, err)
val, err := client.Scard("key")
assert.Nil(t, err)
assert.Equal(t, int64(4), val)
_, err = New(client.Addr, badType()).Sismember("key", 2)
_, err = newRedis(client.Addr, badType()).Sismember("key", 2)
assert.NotNil(t, err)
ok, err := client.Sismember("key", 2)
assert.Nil(t, err)
assert.True(t, ok)
_, err = New(client.Addr, badType()).Srem("key", 3, 4)
_, err = newRedis(client.Addr, badType()).Srem("key", 3, 4)
assert.NotNil(t, err)
num, err = client.Srem("key", 3, 4)
assert.Nil(t, err)
assert.Equal(t, 2, num)
_, err = New(client.Addr, badType()).Smembers("key")
_, err = newRedis(client.Addr, badType()).Smembers("key")
assert.NotNil(t, err)
vals, err := client.Smembers("key")
assert.Nil(t, err)
assert.ElementsMatch(t, []string{"1", "2"}, vals)
_, err = New(client.Addr, badType()).Srandmember("key", 1)
_, err = newRedis(client.Addr, badType()).Srandmember("key", 1)
assert.NotNil(t, err)
members, err := client.Srandmember("key", 1)
assert.Nil(t, err)
assert.Len(t, members, 1)
assert.Contains(t, []string{"1", "2"}, members[0])
_, err = New(client.Addr, badType()).Spop("key")
_, err = newRedis(client.Addr, badType()).Spop("key")
assert.NotNil(t, err)
member, err := client.Spop("key")
assert.Nil(t, err)
assert.Contains(t, []string{"1", "2"}, member)
_, err = New(client.Addr, badType()).Smembers("key")
_, err = newRedis(client.Addr, badType()).Smembers("key")
assert.NotNil(t, err)
vals, err = client.Smembers("key")
assert.Nil(t, err)
assert.NotContains(t, vals, member)
_, err = New(client.Addr, badType()).Sadd("key1", 1, 2, 3, 4)
_, err = newRedis(client.Addr, badType()).Sadd("key1", 1, 2, 3, 4)
assert.NotNil(t, err)
num, err = client.Sadd("key1", 1, 2, 3, 4)
assert.Nil(t, err)
@ -989,32 +989,32 @@ func TestRedis_Set(t *testing.T) {
num, err = client.Sadd("key2", 2, 3, 4, 5)
assert.Nil(t, err)
assert.Equal(t, 4, num)
_, err = New(client.Addr, badType()).Sunion("key1", "key2")
_, err = newRedis(client.Addr, badType()).Sunion("key1", "key2")
assert.NotNil(t, err)
vals, err = client.Sunion("key1", "key2")
assert.Nil(t, err)
assert.ElementsMatch(t, []string{"1", "2", "3", "4", "5"}, vals)
_, err = New(client.Addr, badType()).Sunionstore("key3", "key1", "key2")
_, err = newRedis(client.Addr, badType()).Sunionstore("key3", "key1", "key2")
assert.NotNil(t, err)
num, err = client.Sunionstore("key3", "key1", "key2")
assert.Nil(t, err)
assert.Equal(t, 5, num)
_, err = New(client.Addr, badType()).Sdiff("key1", "key2")
_, err = newRedis(client.Addr, badType()).Sdiff("key1", "key2")
assert.NotNil(t, err)
vals, err = client.Sdiff("key1", "key2")
assert.Nil(t, err)
assert.EqualValues(t, []string{"1"}, vals)
_, err = New(client.Addr, badType()).Sdiffstore("key4", "key1", "key2")
_, err = newRedis(client.Addr, badType()).Sdiffstore("key4", "key1", "key2")
assert.NotNil(t, err)
num, err = client.Sdiffstore("key4", "key1", "key2")
assert.Nil(t, err)
assert.Equal(t, 1, num)
_, err = New(client.Addr, badType()).Sinter("key1", "key2")
_, err = newRedis(client.Addr, badType()).Sinter("key1", "key2")
assert.NotNil(t, err)
vals, err = client.Sinter("key1", "key2")
assert.Nil(t, err)
assert.ElementsMatch(t, []string{"2", "3", "4"}, vals)
_, err = New(client.Addr, badType()).Sinterstore("key4", "key1", "key2")
_, err = newRedis(client.Addr, badType()).Sinterstore("key4", "key1", "key2")
assert.NotNil(t, err)
num, err = client.Sinterstore("key4", "key1", "key2")
assert.Nil(t, err)
@ -1044,7 +1044,7 @@ func TestRedis_Set(t *testing.T) {
func TestRedis_GetSet(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := New(client.Addr, badType()).GetSet("hello", "world")
_, err := newRedis(client.Addr, badType()).GetSet("hello", "world")
assert.NotNil(t, err)
val, err := client.GetSet("hello", "world")
assert.Nil(t, err)
@ -1066,11 +1066,11 @@ func TestRedis_GetSet(t *testing.T) {
func TestRedis_SetGetDel(t *testing.T) {
runOnRedis(t, func(client *Redis) {
err := New(client.Addr, badType()).Set("hello", "world")
err := newRedis(client.Addr, badType()).Set("hello", "world")
assert.NotNil(t, err)
err = client.Set("hello", "world")
assert.Nil(t, err)
_, err = New(client.Addr, badType()).Get("hello")
_, err = newRedis(client.Addr, badType()).Get("hello")
assert.NotNil(t, err)
val, err := client.Get("hello")
assert.Nil(t, err)
@ -1083,11 +1083,11 @@ func TestRedis_SetGetDel(t *testing.T) {
func TestRedis_SetExNx(t *testing.T) {
runOnRedis(t, func(client *Redis) {
err := New(client.Addr, badType()).Setex("hello", "world", 5)
err := newRedis(client.Addr, badType()).Setex("hello", "world", 5)
assert.NotNil(t, err)
err = client.Setex("hello", "world", 5)
assert.Nil(t, err)
_, err = New(client.Addr, badType()).Setnx("hello", "newworld")
_, err = newRedis(client.Addr, badType()).Setnx("hello", "newworld")
assert.NotNil(t, err)
ok, err := client.Setnx("hello", "newworld")
assert.Nil(t, err)
@ -1104,7 +1104,7 @@ func TestRedis_SetExNx(t *testing.T) {
ttl, err := client.Ttl("hello")
assert.Nil(t, err)
assert.True(t, ttl > 0)
_, err = New(client.Addr, badType()).SetnxEx("newhello", "newworld", 5)
_, err = newRedis(client.Addr, badType()).SetnxEx("newhello", "newworld", 5)
assert.NotNil(t, err)
ok, err = client.SetnxEx("newhello", "newworld", 5)
assert.Nil(t, err)
@ -1126,17 +1126,17 @@ func TestRedis_SetGetDelHashField(t *testing.T) {
runOnRedis(t, func(client *Redis) {
err := client.Hset("key", "field", "value")
assert.Nil(t, err)
_, err = New(client.Addr, badType()).Hget("key", "field")
_, err = newRedis(client.Addr, badType()).Hget("key", "field")
assert.NotNil(t, err)
val, err := client.Hget("key", "field")
assert.Nil(t, err)
assert.Equal(t, "value", val)
_, err = New(client.Addr, badType()).Hexists("key", "field")
_, err = newRedis(client.Addr, badType()).Hexists("key", "field")
assert.NotNil(t, err)
ok, err := client.Hexists("key", "field")
assert.Nil(t, err)
assert.True(t, ok)
_, err = New(client.Addr, badType()).Hdel("key", "field")
_, err = newRedis(client.Addr, badType()).Hdel("key", "field")
assert.NotNil(t, err)
ret, err := client.Hdel("key", "field")
assert.Nil(t, err)
@ -1179,17 +1179,17 @@ func TestRedis_SortedSet(t *testing.T) {
val, err := client.Zscore("key", "value1")
assert.Nil(t, err)
assert.Equal(t, int64(2), val)
_, err = New(client.Addr, badType()).Zincrby("key", 3, "value1")
_, err = newRedis(client.Addr, badType()).Zincrby("key", 3, "value1")
assert.NotNil(t, err)
val, err = client.Zincrby("key", 3, "value1")
assert.Nil(t, err)
assert.Equal(t, int64(5), val)
_, err = New(client.Addr, badType()).Zscore("key", "value1")
_, err = newRedis(client.Addr, badType()).Zscore("key", "value1")
assert.NotNil(t, err)
val, err = client.Zscore("key", "value1")
assert.Nil(t, err)
assert.Equal(t, int64(5), val)
_, err = New(client.Addr, badType()).Zadds("key")
_, err = newRedis(client.Addr, badType()).Zadds("key")
assert.NotNil(t, err)
val, err = client.Zadds("key", Pair{
Key: "value2",
@ -1200,7 +1200,7 @@ func TestRedis_SortedSet(t *testing.T) {
})
assert.Nil(t, err)
assert.Equal(t, int64(2), val)
_, err = New(client.Addr, badType()).ZRevRangeWithScores("key", 1, 3)
_, err = newRedis(client.Addr, badType()).ZRevRangeWithScores("key", 1, 3)
assert.NotNil(t, err)
_, err = client.ZRevRangeWithScores("key", 1, 3)
assert.Nil(t, err)
@ -1224,11 +1224,11 @@ func TestRedis_SortedSet(t *testing.T) {
rank, err = client.Zrevrank("key", "value1")
assert.Nil(t, err)
assert.Equal(t, int64(2), rank)
_, err = New(client.Addr, badType()).Zrank("key", "value4")
_, err = newRedis(client.Addr, badType()).Zrank("key", "value4")
assert.NotNil(t, err)
_, err = client.Zrank("key", "value4")
assert.Equal(t, Nil, err)
_, err = New(client.Addr, badType()).Zrem("key", "value2", "value3")
_, err = newRedis(client.Addr, badType()).Zrem("key", "value2", "value3")
assert.NotNil(t, err)
num, err := client.Zrem("key", "value2", "value3")
assert.Nil(t, err)
@ -1242,7 +1242,7 @@ func TestRedis_SortedSet(t *testing.T) {
ok, err = client.Zadd("key", 8, "value4")
assert.Nil(t, err)
assert.True(t, ok)
_, err = New(client.Addr, badType()).Zremrangebyscore("key", 6, 7)
_, err = newRedis(client.Addr, badType()).Zremrangebyscore("key", 6, 7)
assert.NotNil(t, err)
num, err = client.Zremrangebyscore("key", 6, 7)
assert.Nil(t, err)
@ -1250,37 +1250,37 @@ func TestRedis_SortedSet(t *testing.T) {
ok, err = client.Zadd("key", 6, "value2")
assert.Nil(t, err)
assert.True(t, ok)
_, err = New(client.Addr, badType()).Zadd("key", 7, "value3")
_, err = newRedis(client.Addr, badType()).Zadd("key", 7, "value3")
assert.NotNil(t, err)
ok, err = client.Zadd("key", 7, "value3")
assert.Nil(t, err)
assert.True(t, ok)
_, err = New(client.Addr, badType()).Zcount("key", 6, 7)
_, err = newRedis(client.Addr, badType()).Zcount("key", 6, 7)
assert.NotNil(t, err)
num, err = client.Zcount("key", 6, 7)
assert.Nil(t, err)
assert.Equal(t, 2, num)
_, err = New(client.Addr, badType()).Zremrangebyrank("key", 1, 2)
_, err = newRedis(client.Addr, badType()).Zremrangebyrank("key", 1, 2)
assert.NotNil(t, err)
num, err = client.Zremrangebyrank("key", 1, 2)
assert.Nil(t, err)
assert.Equal(t, 2, num)
_, err = New(client.Addr, badType()).Zcard("key")
_, err = newRedis(client.Addr, badType()).Zcard("key")
assert.NotNil(t, err)
card, err := client.Zcard("key")
assert.Nil(t, err)
assert.Equal(t, 2, card)
_, err = New(client.Addr, badType()).Zrange("key", 0, -1)
_, err = newRedis(client.Addr, badType()).Zrange("key", 0, -1)
assert.NotNil(t, err)
vals, err := client.Zrange("key", 0, -1)
assert.Nil(t, err)
assert.EqualValues(t, []string{"value1", "value4"}, vals)
_, err = New(client.Addr, badType()).Zrevrange("key", 0, -1)
_, err = newRedis(client.Addr, badType()).Zrevrange("key", 0, -1)
assert.NotNil(t, err)
vals, err = client.Zrevrange("key", 0, -1)
assert.Nil(t, err)
assert.EqualValues(t, []string{"value4", "value1"}, vals)
_, err = New(client.Addr, badType()).ZrangeWithScores("key", 0, -1)
_, err = newRedis(client.Addr, badType()).ZrangeWithScores("key", 0, -1)
assert.NotNil(t, err)
pairs, err = client.ZrangeWithScores("key", 0, -1)
assert.Nil(t, err)
@ -1294,7 +1294,7 @@ func TestRedis_SortedSet(t *testing.T) {
Score: 8,
},
}, pairs)
_, err = New(client.Addr, badType()).ZrangebyscoreWithScores("key", 5, 8)
_, err = newRedis(client.Addr, badType()).ZrangebyscoreWithScores("key", 5, 8)
assert.NotNil(t, err)
pairs, err = client.ZrangebyscoreWithScores("key", 5, 8)
assert.Nil(t, err)
@ -1308,7 +1308,7 @@ func TestRedis_SortedSet(t *testing.T) {
Score: 8,
},
}, pairs)
_, err = New(client.Addr, badType()).ZrangebyscoreWithScoresAndLimit(
_, err = newRedis(client.Addr, badType()).ZrangebyscoreWithScoresAndLimit(
"key", 5, 8, 1, 1)
assert.NotNil(t, err)
pairs, err = client.ZrangebyscoreWithScoresAndLimit("key", 5, 8, 1, 1)
@ -1322,7 +1322,7 @@ func TestRedis_SortedSet(t *testing.T) {
pairs, err = client.ZrangebyscoreWithScoresAndLimit("key", 5, 8, 1, 0)
assert.Nil(t, err)
assert.Equal(t, 0, len(pairs))
_, err = New(client.Addr, badType()).ZrevrangebyscoreWithScores("key", 5, 8)
_, err = newRedis(client.Addr, badType()).ZrevrangebyscoreWithScores("key", 5, 8)
assert.NotNil(t, err)
pairs, err = client.ZrevrangebyscoreWithScores("key", 5, 8)
assert.Nil(t, err)
@ -1336,7 +1336,7 @@ func TestRedis_SortedSet(t *testing.T) {
Score: 5,
},
}, pairs)
_, err = New(client.Addr, badType()).ZrevrangebyscoreWithScoresAndLimit(
_, err = newRedis(client.Addr, badType()).ZrevrangebyscoreWithScoresAndLimit(
"key", 5, 8, 1, 1)
assert.NotNil(t, err)
pairs, err = client.ZrevrangebyscoreWithScoresAndLimit("key", 5, 8, 1, 1)
@ -1350,7 +1350,7 @@ func TestRedis_SortedSet(t *testing.T) {
pairs, err = client.ZrevrangebyscoreWithScoresAndLimit("key", 5, 8, 1, 0)
assert.Nil(t, err)
assert.Equal(t, 0, len(pairs))
_, err = New(client.Addr, badType()).Zrevrank("key", "value")
_, err = newRedis(client.Addr, badType()).Zrevrank("key", "value")
assert.NotNil(t, err)
_, _ = client.Zadd("second", 2, "aa")
_, _ = client.Zadd("third", 3, "bbb")
@ -1361,7 +1361,7 @@ func TestRedis_SortedSet(t *testing.T) {
})
assert.Nil(t, err)
assert.Equal(t, int64(2), val)
_, err = New(client.Addr, badType()).Zunionstore("union", &ZStore{})
_, err = newRedis(client.Addr, badType()).Zunionstore("union", &ZStore{})
assert.NotNil(t, err)
vals, err = client.Zrange("union", 0, 10000)
assert.Nil(t, err)
@ -1488,10 +1488,10 @@ func TestRedis_SortedSetByFloat64(t *testing.T) {
val, err := client.ZscoreByFloat("key", "value1")
assert.Nil(t, err)
assert.Equal(t, 10.345, val)
_, err = New(client.Addr, badType()).ZscoreByFloat("key", "value1")
_, err = newRedis(client.Addr, badType()).ZscoreByFloat("key", "value1")
assert.Error(t, err)
_, _ = client.ZaddFloat("key", 10.346, "value2")
_, err = New(client.Addr, badType()).ZRevRangeWithScoresByFloat("key", 0, -1)
_, err = newRedis(client.Addr, badType()).ZRevRangeWithScoresByFloat("key", 0, -1)
assert.NotNil(t, err)
_, err = client.ZRevRangeWithScoresByFloat("key", 0, -1)
assert.Nil(t, err)
@ -1510,7 +1510,7 @@ func TestRedis_SortedSetByFloat64(t *testing.T) {
},
}, pairs)
_, err = New(client.Addr, badType()).ZrangeWithScoresByFloat("key", 0, -1)
_, err = newRedis(client.Addr, badType()).ZrangeWithScoresByFloat("key", 0, -1)
assert.Error(t, err)
pairs, err = client.ZrangeWithScoresByFloat("key", 0, -1)
@ -1527,7 +1527,7 @@ func TestRedis_SortedSetByFloat64(t *testing.T) {
}, pairs)
}
_, err = New(client.Addr, badType()).ZrangebyscoreWithScoresByFloat("key", 0, 20)
_, err = newRedis(client.Addr, badType()).ZrangebyscoreWithScoresByFloat("key", 0, 20)
assert.NotNil(t, err)
pairs, err = client.ZrangebyscoreWithScoresByFloat("key", 0, 20)
assert.Nil(t, err)
@ -1543,7 +1543,7 @@ func TestRedis_SortedSetByFloat64(t *testing.T) {
}, pairs)
_, err = client.ZrangebyscoreWithScoresByFloatAndLimit("key", 10.1, 12.2, 1, 0)
assert.NoError(t, err)
_, err = New(client.Addr, badType()).ZrangebyscoreWithScoresByFloatAndLimit(
_, err = newRedis(client.Addr, badType()).ZrangebyscoreWithScoresByFloatAndLimit(
"key", 10.1, 12.2, 1, 1)
assert.NotNil(t, err)
pairs, err = client.ZrangebyscoreWithScoresByFloatAndLimit("key", 10.1, 12.2, 1, 1)
@ -1554,7 +1554,7 @@ func TestRedis_SortedSetByFloat64(t *testing.T) {
Score: 10.346,
},
}, pairs)
_, err = New(client.Addr, badType()).ZrevrangebyscoreWithScoresByFloat("key", 10, 12)
_, err = newRedis(client.Addr, badType()).ZrevrangebyscoreWithScoresByFloat("key", 10, 12)
assert.NotNil(t, err)
pairs, err = client.ZrevrangebyscoreWithScoresByFloat("key", 10, 12)
assert.Nil(t, err)
@ -1570,7 +1570,7 @@ func TestRedis_SortedSetByFloat64(t *testing.T) {
}, pairs)
_, err = client.ZrevrangebyscoreWithScoresByFloatAndLimit("key", 10, 12, 1, 0)
assert.NoError(t, err)
_, err = New(client.Addr, badType()).ZrevrangebyscoreWithScoresByFloatAndLimit(
_, err = newRedis(client.Addr, badType()).ZrevrangebyscoreWithScoresByFloatAndLimit(
"key", 10, 12, 1, 1)
assert.NotNil(t, err)
pairs, err = client.ZrevrangebyscoreWithScoresByFloatAndLimit("key", 10, 12, 1, 1)
@ -1586,19 +1586,27 @@ func TestRedis_SortedSetByFloat64(t *testing.T) {
func TestRedis_Zaddnx(t *testing.T) {
runOnRedis(t, func(client *Redis) {
_, err := newRedis(client.Addr, badType()).Zaddnx("key", 1, "value1")
assert.Error(t, err)
ok, err := client.Zadd("key", 1, "value1")
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, ok)
ok, err = client.Zaddnx("key", 2, "value1")
assert.Nil(t, err)
assert.NoError(t, err)
assert.False(t, ok)
ok, err = client.ZaddFloat("key", 1.1, "value2")
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, ok)
ok, err = client.ZaddnxFloat("key", 1.1, "value3")
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, ok)
assert.NoError(t, client.Set("newkey", "value"))
ok, err = client.Zaddnx("newkey", 1, "value")
assert.Error(t, err)
assert.False(t, ok)
})
}
@ -1607,12 +1615,12 @@ func TestRedis_IncrbyFloat(t *testing.T) {
incrVal, err := client.IncrbyFloat("key", 0.002)
assert.Nil(t, err)
assert.Equal(t, 0.002, incrVal)
_, err = New(client.Addr, badType()).IncrbyFloat("key", -0.001)
_, err = newRedis(client.Addr, badType()).IncrbyFloat("key", -0.001)
assert.Error(t, err)
incrVal2, err := client.IncrbyFloat("key", -0.001)
assert.Nil(t, err)
assert.Equal(t, 0.001, incrVal2)
_, err = New(client.Addr, badType()).HincrbyFloat("hkey", "i", 0.002)
_, err = newRedis(client.Addr, badType()).HincrbyFloat("hkey", "i", 0.002)
assert.Error(t, err)
hincrVal, err := client.HincrbyFloat("hkey", "i", 0.002)
assert.Nil(t, err)
@ -1625,7 +1633,7 @@ func TestRedis_IncrbyFloat(t *testing.T) {
func TestRedis_Pipelined(t *testing.T) {
runOnRedis(t, func(client *Redis) {
assert.NotNil(t, New(client.Addr, badType()).Pipelined(func(pipeliner Pipeliner) error {
assert.NotNil(t, newRedis(client.Addr, badType()).Pipelined(func(pipeliner Pipeliner) error {
return nil
}))
err := client.Pipelined(
@ -1637,7 +1645,7 @@ func TestRedis_Pipelined(t *testing.T) {
},
)
assert.Nil(t, err)
_, err = New(client.Addr, badType()).Ttl("pipelined_counter")
_, err = newRedis(client.Addr, badType()).Ttl("pipelined_counter")
assert.NotNil(t, err)
ttl, err := client.Ttl("pipelined_counter")
assert.Nil(t, err)
@ -1654,17 +1662,17 @@ func TestRedis_Pipelined(t *testing.T) {
func TestRedisString(t *testing.T) {
runOnRedis(t, func(client *Redis) {
client.Ping()
_, err := getRedis(New(client.Addr, Cluster()))
_, err := getRedis(newRedis(client.Addr, Cluster()))
assert.Nil(t, err)
assert.Equal(t, client.Addr, client.String())
assert.NotNil(t, New(client.Addr, badType()).Ping())
assert.NotNil(t, newRedis(client.Addr, badType()).Ping())
})
}
func TestRedisScriptLoad(t *testing.T) {
runOnRedis(t, func(client *Redis) {
client.Ping()
_, err := New(client.Addr, badType()).ScriptLoad("foo")
_, err := newRedis(client.Addr, badType()).ScriptLoad("foo")
assert.NotNil(t, err)
_, err = client.ScriptLoad("foo")
assert.NotNil(t, err)
@ -1676,7 +1684,7 @@ func TestRedisEvalSha(t *testing.T) {
client.Ping()
scriptHash, err := client.ScriptLoad(`return redis.call("EXISTS", KEYS[1])`)
assert.Nil(t, err)
_, err = New(client.Addr, badType()).EvalSha(scriptHash, []string{"key1"})
_, err = newRedis(client.Addr, badType()).EvalSha(scriptHash, []string{"key1"})
assert.Error(t, err)
result, err := client.EvalSha(scriptHash, []string{"key1"})
assert.Nil(t, err)
@ -1759,7 +1767,7 @@ func TestRedis_Zscan(t *testing.T) {
var cursor uint64 = 0
sum := 0
for {
_, _, err := New(client.Addr, badType()).Zscan(key, cursor, "value_*", 100)
_, _, err := newRedis(client.Addr, badType()).Zscan(key, cursor, "value_*", 100)
assert.NotNil(t, err)
keys, next, err := client.Zscan(key, cursor, "value_*", 100)
assert.Nil(t, err)
@ -1771,7 +1779,7 @@ func TestRedis_Zscan(t *testing.T) {
}
assert.Equal(t, sum, 3100)
_, err := New(client.Addr, badType()).Del(key)
_, err := newRedis(client.Addr, badType()).Del(key)
assert.NotNil(t, err)
_, err = client.Del(key)
assert.Nil(t, err)
@ -1827,13 +1835,13 @@ func TestRedisGeo(t *testing.T) {
v, err := client.GeoAdd("sicily", geoLocation...)
assert.Nil(t, err)
assert.Equal(t, int64(2), v)
_, err = New(client.Addr, badType()).GeoDist("sicily", "Palermo", "Catania", "m")
_, err = newRedis(client.Addr, badType()).GeoDist("sicily", "Palermo", "Catania", "m")
assert.Error(t, err)
v2, err := client.GeoDist("sicily", "Palermo", "Catania", "m")
assert.Nil(t, err)
assert.Equal(t, 166274, int(v2))
// GeoHash not support
_, err = New(client.Addr, badType()).GeoPos("sicily", "Palermo", "Catania")
_, err = newRedis(client.Addr, badType()).GeoPos("sicily", "Palermo", "Catania")
assert.Error(t, err)
v3, err := client.GeoPos("sicily", "Palermo", "Catania")
assert.Nil(t, err)
@ -1841,7 +1849,7 @@ func TestRedisGeo(t *testing.T) {
assert.Equal(t, int64(v3[0].Latitude), int64(38))
assert.Equal(t, int64(v3[1].Longitude), int64(15))
assert.Equal(t, int64(v3[1].Latitude), int64(37))
_, err = New(client.Addr, badType()).GeoRadius("sicily", 15, 37,
_, err = newRedis(client.Addr, badType()).GeoRadius("sicily", 15, 37,
&red.GeoRadiusQuery{WithDist: true, Unit: "km", Radius: 200})
assert.Error(t, err)
v4, err := client.GeoRadius("sicily", 15, 37, &red.GeoRadiusQuery{
@ -1852,12 +1860,12 @@ func TestRedisGeo(t *testing.T) {
assert.Equal(t, int64(v4[0].Dist), int64(190))
assert.Equal(t, int64(v4[1].Dist), int64(56))
geoLocation2 := []*GeoLocation{{Longitude: 13.583333, Latitude: 37.316667, Name: "Agrigento"}}
_, err = New(client.Addr, badType()).GeoAdd("sicily", geoLocation2...)
_, err = newRedis(client.Addr, badType()).GeoAdd("sicily", geoLocation2...)
assert.Error(t, err)
v5, err := client.GeoAdd("sicily", geoLocation2...)
assert.Nil(t, err)
assert.Equal(t, int64(1), v5)
_, err = New(client.Addr, badType()).GeoRadiusByMember("sicily", "Agrigento",
_, err = newRedis(client.Addr, badType()).GeoRadiusByMember("sicily", "Agrigento",
&red.GeoRadiusQuery{Unit: "km", Radius: 100})
assert.Error(t, err)
v6, err := client.GeoRadiusByMember("sicily", "Agrigento",
@ -1904,7 +1912,7 @@ func TestSetSlowThreshold(t *testing.T) {
func TestRedis_WithPass(t *testing.T) {
runOnRedis(t, func(client *Redis) {
err := New(client.Addr, WithPass("any")).Ping()
err := newRedis(client.Addr, WithPass("any")).Ping()
assert.NotNil(t, err)
})
}
@ -1924,7 +1932,7 @@ func runOnRedisWithError(t *testing.T, fn func(client *Redis)) {
s := miniredis.RunT(t)
s.SetError("mock error")
fn(New(s.Addr()))
fn(newRedis(s.Addr()))
}
func runOnRedisTLS(t *testing.T, fn func(client *Redis)) {
@ -1946,7 +1954,7 @@ func runOnRedisTLS(t *testing.T, fn func(client *Redis)) {
_ = client.Close()
}
}()
fn(New(s.Addr(), WithTLS()))
fn(newRedis(s.Addr(), WithTLS()))
}
func badType() Option {

Loading…
Cancel
Save