forked from mirror/redis
Add SRandMemberN. Fixes #155.
This commit is contained in:
parent
73e1e9f501
commit
9ead45f9e9
|
@ -944,12 +944,20 @@ func (c *commandable) SPop(key string) *StringCmd {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Redis `SRANDMEMBER key` command.
|
||||||
func (c *commandable) SRandMember(key string) *StringCmd {
|
func (c *commandable) SRandMember(key string) *StringCmd {
|
||||||
cmd := NewStringCmd("SRANDMEMBER", key)
|
cmd := NewStringCmd("SRANDMEMBER", key)
|
||||||
c.Process(cmd)
|
c.Process(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Redis `SRANDMEMBER key count` command.
|
||||||
|
func (c *commandable) SRandMemberN(key string, count int64) *StringSliceCmd {
|
||||||
|
cmd := NewStringSliceCmd("SRANDMEMBER", key, formatInt(count))
|
||||||
|
c.Process(cmd)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
func (c *commandable) SRem(key string, members ...string) *IntCmd {
|
func (c *commandable) SRem(key string, members ...string) *IntCmd {
|
||||||
args := make([]interface{}, 2+len(members))
|
args := make([]interface{}, 2+len(members))
|
||||||
args[0] = "SREM"
|
args[0] = "SREM"
|
||||||
|
|
|
@ -1733,21 +1733,25 @@ var _ = Describe("Commands", func() {
|
||||||
Expect(sMembers.Val()).To(HaveLen(2))
|
Expect(sMembers.Val()).To(HaveLen(2))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should SRandMember", func() {
|
It("should SRandMember and SRandMemberN", func() {
|
||||||
sAdd := client.SAdd("set", "one")
|
err := client.SAdd("set", "one").Err()
|
||||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
sAdd = client.SAdd("set", "two")
|
err = client.SAdd("set", "two").Err()
|
||||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
sAdd = client.SAdd("set", "three")
|
err = client.SAdd("set", "three").Err()
|
||||||
Expect(sAdd.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
sRandMember := client.SRandMember("set")
|
members, err := client.SMembers("set").Result()
|
||||||
Expect(sRandMember.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(sRandMember.Val()).NotTo(Equal(""))
|
Expect(members).To(HaveLen(3))
|
||||||
|
|
||||||
sMembers := client.SMembers("set")
|
member, err := client.SRandMember("set").Result()
|
||||||
Expect(sMembers.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(sMembers.Val()).To(HaveLen(3))
|
Expect(member).NotTo(Equal(""))
|
||||||
|
|
||||||
|
members, err = client.SRandMemberN("set", 2).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(members).To(HaveLen(2))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should SRem", func() {
|
It("should SRem", func() {
|
||||||
|
|
Loading…
Reference in New Issue