From 5ed546f303dae50ac28e5b9296c2b1523119fd4c Mon Sep 17 00:00:00 2001 From: nigel_li Date: Wed, 28 Apr 2021 13:56:44 +0800 Subject: [PATCH] Add command SMISMEMBER --- commands.go | 12 ++++++++++++ commands_test.go | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/commands.go b/commands.go index 65ca464..0926b87 100644 --- a/commands.go +++ b/commands.go @@ -201,6 +201,7 @@ type Cmdable interface { SInter(ctx context.Context, keys ...string) *StringSliceCmd 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 SMembers(ctx context.Context, key string) *StringSliceCmd SMembersMap(ctx context.Context, key string) *StringStructMapCmd SMove(ctx context.Context, source, destination string, member interface{}) *BoolCmd @@ -1530,6 +1531,17 @@ func (c cmdable) SIsMember(ctx context.Context, key string, member interface{}) return cmd } +// Redis `SMISMEMBER key member [member ...]` command. +func (c cmdable) SMIsMember(ctx context.Context, key string, members ...interface{}) *BoolSliceCmd { + args := make([]interface{}, 2, 2+len(members)) + args[0] = "smismember" + args[1] = key + args = appendArgs(args, members) + cmd := NewBoolSliceCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} + // Redis `SMEMBERS key` command output as a slice. func (c cmdable) SMembers(ctx context.Context, key string) *StringSliceCmd { cmd := NewStringSliceCmd(ctx, "smembers", key) diff --git a/commands_test.go b/commands_test.go index 1449587..fb492bf 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2500,6 +2500,15 @@ var _ = Describe("Commands", func() { Expect(sIsMember.Val()).To(Equal(false)) }) + It("should SMIsMember", func() { + sAdd := client.SAdd(ctx, "set", "one") + Expect(sAdd.Err()).NotTo(HaveOccurred()) + + sMIsMember := client.SMIsMember(ctx, "set", "one", "two") + Expect(sMIsMember.Err()).NotTo(HaveOccurred()) + Expect(sMIsMember.Val()).To(Equal([]bool{true, false})) + }) + It("should SMembers", func() { sAdd := client.SAdd(ctx, "set", "Hello") Expect(sAdd.Err()).NotTo(HaveOccurred())