mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
Add Sinter,Sinterstore & Modify TestRedis_Set (#779)
* Add Sinter,Sinterstore; Modify TestRedis_Set * Update redis_test.go fix test failure Co-authored-by: lucq <lucq@toopsoon.com> Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
parent
b0739d63c0
commit
c9a2a60e28
@ -1282,6 +1282,41 @@ func (s *Redis) Sdiffstore(destination string, keys ...string) (val int, err err
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sinter is the implementation of redis sinter command.
|
||||||
|
func (s *Redis) Sinter(keys ...string) (val []string, err error) {
|
||||||
|
err = s.brk.DoWithAcceptable(func() error {
|
||||||
|
conn, err := getRedis(s)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err = conn.SInter(keys...).Result()
|
||||||
|
return err
|
||||||
|
}, acceptable)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sinterstore is the implementation of redis sinterstore command.
|
||||||
|
func (s *Redis) Sinterstore(destination string, keys ...string) (val int, err error) {
|
||||||
|
err = s.brk.DoWithAcceptable(func() error {
|
||||||
|
conn, err := getRedis(s)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
v, err := conn.SInterStore(destination, keys...).Result()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
val = int(v)
|
||||||
|
return nil
|
||||||
|
}, acceptable)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Ttl is the implementation of redis ttl command.
|
// Ttl is the implementation of redis ttl command.
|
||||||
func (s *Redis) Ttl(key string) (val int, err error) {
|
func (s *Redis) Ttl(key string) (val int, err error) {
|
||||||
err = s.brk.DoWithAcceptable(func() error {
|
err = s.brk.DoWithAcceptable(func() error {
|
||||||
|
@ -638,6 +638,16 @@ func TestRedis_Set(t *testing.T) {
|
|||||||
num, err = client.Sdiffstore("key4", "key1", "key2")
|
num, err = client.Sdiffstore("key4", "key1", "key2")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, 1, num)
|
assert.Equal(t, 1, num)
|
||||||
|
_, err = New(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")
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
num, err = client.Sinterstore("key4", "key1", "key2")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, 3, num)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user