forked from mirror/redis
Merge pull request #329 from fishbrain/add-support-for-spopn
Add support for SPOP with a count argument
This commit is contained in:
commit
a905127dc8
|
@ -959,12 +959,20 @@ func (c *commandable) SMove(source, destination string, member interface{}) *Boo
|
|||
return cmd
|
||||
}
|
||||
|
||||
// Redis `SPOP key` command.
|
||||
func (c *commandable) SPop(key string) *StringCmd {
|
||||
cmd := NewStringCmd("SPOP", key)
|
||||
c.Process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Redis `SPOP key count` command.
|
||||
func (c *commandable) SPopN(key string, count int64) *StringSliceCmd {
|
||||
cmd := NewStringSliceCmd("SPOP", key, count)
|
||||
c.Process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Redis `SRANDMEMBER key` command.
|
||||
func (c *commandable) SRandMember(key string) *StringCmd {
|
||||
cmd := NewStringCmd("SRANDMEMBER", key)
|
||||
|
|
|
@ -1819,6 +1819,34 @@ var _ = Describe("Commands", func() {
|
|||
sMembers := client.SMembers("set")
|
||||
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
||||
Expect(sMembers.Val()).To(HaveLen(2))
|
||||
|
||||
})
|
||||
|
||||
It("should SPopN", func() {
|
||||
sAdd := client.SAdd("set", "one")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
sAdd = client.SAdd("set", "two")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
sAdd = client.SAdd("set", "three")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
sAdd = client.SAdd("set", "four")
|
||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
||||
|
||||
sPopN := client.SPopN("set", 1)
|
||||
Expect(sPopN.Err()).NotTo(HaveOccurred())
|
||||
Expect(sPopN.Val()).NotTo(Equal([]string{""}))
|
||||
|
||||
sMembers := client.SMembers("set")
|
||||
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
||||
Expect(sMembers.Val()).To(HaveLen(3))
|
||||
|
||||
sPopN = client.SPopN("set", 4)
|
||||
Expect(sPopN.Err()).NotTo(HaveOccurred())
|
||||
Expect(sPopN.Val()).To(HaveLen(3))
|
||||
|
||||
sMembers = client.SMembers("set")
|
||||
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
||||
Expect(sMembers.Val()).To(HaveLen(0))
|
||||
})
|
||||
|
||||
It("should SRandMember and SRandMemberN", func() {
|
||||
|
|
Loading…
Reference in New Issue