mirror of https://github.com/go-redis/redis.git
Merge pull request #2291 from boatrainlsz/master
feat: add support for SINTERCARD command
This commit is contained in:
commit
5502cf6c3a
17
commands.go
17
commands.go
|
@ -207,6 +207,7 @@ type Cmdable interface {
|
|||
SDiff(ctx context.Context, keys ...string) *StringSliceCmd
|
||||
SDiffStore(ctx context.Context, destination string, keys ...string) *IntCmd
|
||||
SInter(ctx context.Context, keys ...string) *StringSliceCmd
|
||||
SInterCard(ctx context.Context, limit int64, keys ...string) *IntCmd
|
||||
SInterStore(ctx context.Context, destination string, keys ...string) *IntCmd
|
||||
SIsMember(ctx context.Context, key string, member interface{}) *BoolCmd
|
||||
SMIsMember(ctx context.Context, key string, members ...interface{}) *BoolSliceCmd
|
||||
|
@ -1612,6 +1613,22 @@ func (c cmdable) SInter(ctx context.Context, keys ...string) *StringSliceCmd {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (c cmdable) SInterCard(ctx context.Context, limit int64, keys ...string) *IntCmd {
|
||||
args := make([]interface{}, 4+len(keys))
|
||||
args[0] = "sintercard"
|
||||
numkeys := int64(0)
|
||||
for i, key := range keys {
|
||||
args[2+i] = key
|
||||
numkeys++
|
||||
}
|
||||
args[1] = numkeys
|
||||
args[2+numkeys] = "limit"
|
||||
args[3+numkeys] = limit
|
||||
cmd := NewIntCmd(ctx, args...)
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c cmdable) SInterStore(ctx context.Context, destination string, keys ...string) *IntCmd {
|
||||
args := make([]interface{}, 2+len(keys))
|
||||
args[0] = "sinterstore"
|
||||
|
|
|
@ -2551,6 +2551,36 @@ var _ = Describe("Commands", func() {
|
|||
Expect(sInter.Val()).To(Equal([]string{"c"}))
|
||||
})
|
||||
|
||||
It("should SInterCard", func() {
|
||||
sAdd := client.SAdd(ctx, "set1", "a")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
sAdd = client.SAdd(ctx, "set1", "b")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
sAdd = client.SAdd(ctx, "set1", "c")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
|
||||
sAdd = client.SAdd(ctx, "set2", "b")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
sAdd = client.SAdd(ctx, "set2", "c")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
sAdd = client.SAdd(ctx, "set2", "d")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
sAdd = client.SAdd(ctx, "set2", "e")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
//limit 0 means no limit,see https://redis.io/commands/sintercard/ for more details
|
||||
sInterCard := client.SInterCard(ctx, 0, "set1", "set2")
|
||||
Expect(sInterCard.Err()).NotTo(HaveOccurred())
|
||||
Expect(sInterCard.Val()).To(Equal(int64(2)))
|
||||
|
||||
sInterCard = client.SInterCard(ctx, 1, "set1", "set2")
|
||||
Expect(sInterCard.Err()).NotTo(HaveOccurred())
|
||||
Expect(sInterCard.Val()).To(Equal(int64(1)))
|
||||
|
||||
sInterCard = client.SInterCard(ctx, 3, "set1", "set2")
|
||||
Expect(sInterCard.Err()).NotTo(HaveOccurred())
|
||||
Expect(sInterCard.Val()).To(Equal(int64(2)))
|
||||
})
|
||||
|
||||
It("should SInterStore", func() {
|
||||
sAdd := client.SAdd(ctx, "set1", "a")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
|
|
Loading…
Reference in New Issue