forked from mirror/redis
Add bytes support for sorted set.
This commit is contained in:
parent
0c19d0be41
commit
379b44f44a
|
@ -978,13 +978,16 @@ func (c *commandable) SUnionStore(destination string, keys ...string) *IntCmd {
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Sorted set member.
|
||||||
type Z struct {
|
type Z struct {
|
||||||
Score float64
|
Score float64
|
||||||
Member string
|
Member interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sorted set store operation.
|
||||||
type ZStore struct {
|
type ZStore struct {
|
||||||
Weights []int64
|
Weights []int64
|
||||||
|
// Can be SUM, MIN or MAX.
|
||||||
Aggregate string
|
Aggregate string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1822,21 +1822,43 @@ var _ = Describe("Commands", func() {
|
||||||
Describe("sorted sets", func() {
|
Describe("sorted sets", func() {
|
||||||
|
|
||||||
It("should ZAdd", func() {
|
It("should ZAdd", func() {
|
||||||
zAdd := client.ZAdd("zset", redis.Z{1, "one"})
|
added, err := client.ZAdd("zset", redis.Z{1, "one"}).Result()
|
||||||
Expect(zAdd.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(zAdd.Val()).To(Equal(int64(1)))
|
Expect(added).To(Equal(int64(1)))
|
||||||
|
|
||||||
zAdd = client.ZAdd("zset", redis.Z{1, "uno"})
|
added, err = client.ZAdd("zset", redis.Z{1, "uno"}).Result()
|
||||||
Expect(zAdd.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(zAdd.Val()).To(Equal(int64(1)))
|
Expect(added).To(Equal(int64(1)))
|
||||||
|
|
||||||
zAdd = client.ZAdd("zset", redis.Z{2, "two"})
|
added, err = client.ZAdd("zset", redis.Z{2, "two"}).Result()
|
||||||
Expect(zAdd.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(zAdd.Val()).To(Equal(int64(1)))
|
Expect(added).To(Equal(int64(1)))
|
||||||
|
|
||||||
zAdd = client.ZAdd("zset", redis.Z{3, "two"})
|
added, err = client.ZAdd("zset", redis.Z{3, "two"}).Result()
|
||||||
Expect(zAdd.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(zAdd.Val()).To(Equal(int64(0)))
|
Expect(added).To(Equal(int64(0)))
|
||||||
|
|
||||||
|
val, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(val).To(Equal([]redis.Z{{1, "one"}, {1, "uno"}, {3, "two"}}))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should ZAdd bytes", func() {
|
||||||
|
added, err := client.ZAdd("zset", redis.Z{1, []byte("one")}).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(added).To(Equal(int64(1)))
|
||||||
|
|
||||||
|
added, err = client.ZAdd("zset", redis.Z{1, []byte("uno")}).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(added).To(Equal(int64(1)))
|
||||||
|
|
||||||
|
added, err = client.ZAdd("zset", redis.Z{2, []byte("two")}).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(added).To(Equal(int64(1)))
|
||||||
|
|
||||||
|
added, err = client.ZAdd("zset", redis.Z{3, []byte("two")}).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(added).To(Equal(int64(0)))
|
||||||
|
|
||||||
val, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
val, err := client.ZRangeWithScores("zset", 0, -1).Result()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
Loading…
Reference in New Issue