mirror of https://github.com/go-redis/redis.git
feat: add zintercard cmd
Signed-off-by: monkey92t <golang@88.com>
This commit is contained in:
parent
09fcdbe6e4
commit
bb65dcdf09
17
commands.go
17
commands.go
|
@ -268,6 +268,7 @@ type Cmdable interface {
|
|||
ZIncrBy(ctx context.Context, key string, increment float64, member string) *FloatCmd
|
||||
ZInter(ctx context.Context, store *ZStore) *StringSliceCmd
|
||||
ZInterWithScores(ctx context.Context, store *ZStore) *ZSliceCmd
|
||||
ZInterCard(ctx context.Context, limit int64, keys ...string) *IntCmd
|
||||
ZInterStore(ctx context.Context, destination string, store *ZStore) *IntCmd
|
||||
ZMScore(ctx context.Context, key string, members ...string) *FloatSliceCmd
|
||||
ZPopMax(ctx context.Context, key string, count ...int64) *ZSliceCmd
|
||||
|
@ -2346,6 +2347,22 @@ func (c cmdable) ZInterWithScores(ctx context.Context, store *ZStore) *ZSliceCmd
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (c cmdable) ZInterCard(ctx context.Context, limit int64, keys ...string) *IntCmd {
|
||||
args := make([]interface{}, 4+len(keys))
|
||||
args[0] = "zintercard"
|
||||
numkeys := int64(0)
|
||||
for i, key := range keys {
|
||||
args[2+i] = key
|
||||
numkeys++
|
||||
}
|
||||
args[1] = numkeys
|
||||
args[2+numkeys] = "limit"
|
||||
args[3+numkeys] = limit
|
||||
cmd := NewIntCmd(ctx, args...)
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c cmdable) ZMScore(ctx context.Context, key string, members ...string) *FloatSliceCmd {
|
||||
args := make([]interface{}, 2+len(members))
|
||||
args[0] = "zmscore"
|
||||
|
|
|
@ -4353,6 +4353,32 @@ var _ = Describe("Commands", func() {
|
|||
Expect(v).To(Equal([]string{"one", "two"}))
|
||||
})
|
||||
|
||||
It("should ZInterCard", 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())
|
||||
|
||||
// limit 0 means no limit
|
||||
sInterCard := client.ZInterCard(ctx, 0, "zset1", "zset2")
|
||||
Expect(sInterCard.Err()).NotTo(HaveOccurred())
|
||||
Expect(sInterCard.Val()).To(Equal(int64(2)))
|
||||
|
||||
sInterCard = client.ZInterCard(ctx, 1, "zset1", "zset2")
|
||||
Expect(sInterCard.Err()).NotTo(HaveOccurred())
|
||||
Expect(sInterCard.Val()).To(Equal(int64(1)))
|
||||
|
||||
sInterCard = client.ZInterCard(ctx, 3, "zset1", "zset2")
|
||||
Expect(sInterCard.Err()).NotTo(HaveOccurred())
|
||||
Expect(sInterCard.Val()).To(Equal(int64(2)))
|
||||
})
|
||||
|
||||
It("should ZInterWithScores", func() {
|
||||
err := client.ZAdd(ctx, "zset1", redis.Z{Score: 1, Member: "one"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
|
Loading…
Reference in New Issue