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:
lucaq 2021-06-23 10:46:16 +08:00 committed by GitHub
parent b0739d63c0
commit c9a2a60e28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View File

@ -1282,6 +1282,41 @@ func (s *Redis) Sdiffstore(destination string, keys ...string) (val int, err err
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.
func (s *Redis) Ttl(key string) (val int, err error) {
err = s.brk.DoWithAcceptable(func() error {

View File

@ -638,6 +638,16 @@ func TestRedis_Set(t *testing.T) {
num, err = client.Sdiffstore("key4", "key1", "key2")
assert.Nil(t, err)
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)
})
}