mirror of https://github.com/go-redis/redis.git
add ZDiffStore command (#1775)
This commit is contained in:
parent
74246e0ccf
commit
036605d7c6
13
commands.go
13
commands.go
|
@ -281,6 +281,7 @@ type Cmdable interface {
|
|||
ZRandMember(ctx context.Context, key string, count int, withScores bool) *StringSliceCmd
|
||||
ZDiff(ctx context.Context, keys ...string) *StringSliceCmd
|
||||
ZDiffWithScores(ctx context.Context, keys ...string) *ZSliceCmd
|
||||
ZDiffStore(ctx context.Context, destination string, keys ...string) *IntCmd
|
||||
|
||||
PFAdd(ctx context.Context, key string, els ...interface{}) *IntCmd
|
||||
PFCount(ctx context.Context, keys ...string) *IntCmd
|
||||
|
@ -2458,6 +2459,18 @@ func (c cmdable) ZDiffWithScores(ctx context.Context, keys ...string) *ZSliceCmd
|
|||
return cmd
|
||||
}
|
||||
|
||||
// redis-server version >=6.2.0.
|
||||
func (c cmdable) ZDiffStore(ctx context.Context, destination string, keys ...string) *IntCmd {
|
||||
args := make([]interface{}, 0, 3+len(keys))
|
||||
args = append(args, "zdiffstore", destination, len(keys))
|
||||
for _, key := range keys {
|
||||
args = append(args, key)
|
||||
}
|
||||
cmd := NewIntCmd(ctx, args...)
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
func (c cmdable) PFAdd(ctx context.Context, key string, els ...interface{}) *IntCmd {
|
||||
|
|
|
@ -4048,6 +4048,31 @@ var _ = Describe("Commands", func() {
|
|||
},
|
||||
}))
|
||||
})
|
||||
|
||||
It("should ZDiffStore", func() {
|
||||
err := client.ZAdd(ctx, "zset1", &redis.Z{Score: 1, Member: "one"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = client.ZAdd(ctx, "zset1", &redis.Z{Score: 2, Member: "two"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = client.ZAdd(ctx, "zset2", &redis.Z{Score: 1, Member: "one"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = client.ZAdd(ctx, "zset2", &redis.Z{Score: 2, Member: "two"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = client.ZAdd(ctx, "zset2", &redis.Z{Score: 3, Member: "three"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
v, err := client.ZDiffStore(ctx, "out1", "zset1", "zset2").Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(int64(0)))
|
||||
v, err = client.ZDiffStore(ctx, "out1", "zset2", "zset1").Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(v).To(Equal(int64(1)))
|
||||
vals, err := client.ZRangeWithScores(ctx, "out1", 0, -1).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(vals).To(Equal([]redis.Z{{
|
||||
Score: 3,
|
||||
Member: "three",
|
||||
}}))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("streams", func() {
|
||||
|
|
Loading…
Reference in New Issue