Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should change SIsMember to accept multiple args and use smismember if len(members) > 1. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that these two commands are quite similar, but changing SIsMember to accept multiple args breaks the API compatibility. The current type of return value is *BoolCmd, while the desired is *BoolSliceCmd.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we consider modifying it in v9? they function exactly the same.

Copy link
Contributor Author

@nigelis nigelis Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks acceptable to me.

I can modify the SIsMember and open another PR to branch v9 after you draw the conclusion.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't realized they return different results. No need to merge them then.

SMembers(ctx context.Context, key string) *StringSliceCmd
SMembersMap(ctx context.Context, key string) *StringStructMapCmd
SMove(ctx context.Context, source, destination string, member interface{}) *BoolCmd
Expand Down Expand Up @@ -1508,6 +1509,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)
Expand Down
9 changes: 9 additions & 0 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,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())
Expand Down