diff --git a/commands.go b/commands.go index 2bc10d6..7f10a2f 100644 --- a/commands.go +++ b/commands.go @@ -978,13 +978,16 @@ func (c *commandable) SUnionStore(destination string, keys ...string) *IntCmd { //------------------------------------------------------------------------------ +// Sorted set member. type Z struct { Score float64 - Member string + Member interface{} } +// Sorted set store operation. type ZStore struct { - Weights []int64 + Weights []int64 + // Can be SUM, MIN or MAX. Aggregate string } diff --git a/commands_test.go b/commands_test.go index ae0535e..6cd9fc0 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1822,21 +1822,43 @@ var _ = Describe("Commands", func() { Describe("sorted sets", func() { It("should ZAdd", func() { - zAdd := client.ZAdd("zset", redis.Z{1, "one"}) - Expect(zAdd.Err()).NotTo(HaveOccurred()) - Expect(zAdd.Val()).To(Equal(int64(1))) + added, err := client.ZAdd("zset", redis.Z{1, "one"}).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(added).To(Equal(int64(1))) - zAdd = client.ZAdd("zset", redis.Z{1, "uno"}) - Expect(zAdd.Err()).NotTo(HaveOccurred()) - Expect(zAdd.Val()).To(Equal(int64(1))) + added, err = client.ZAdd("zset", redis.Z{1, "uno"}).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(added).To(Equal(int64(1))) - zAdd = client.ZAdd("zset", redis.Z{2, "two"}) - Expect(zAdd.Err()).NotTo(HaveOccurred()) - Expect(zAdd.Val()).To(Equal(int64(1))) + added, err = client.ZAdd("zset", redis.Z{2, "two"}).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(added).To(Equal(int64(1))) - zAdd = client.ZAdd("zset", redis.Z{3, "two"}) - Expect(zAdd.Err()).NotTo(HaveOccurred()) - Expect(zAdd.Val()).To(Equal(int64(0))) + added, err = client.ZAdd("zset", redis.Z{3, "two"}).Result() + Expect(err).NotTo(HaveOccurred()) + 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() Expect(err).NotTo(HaveOccurred())