@@ -254,6 +254,8 @@ type Cmdable interface {
254254 ZCount (ctx context.Context , key , min , max string ) * IntCmd
255255 ZLexCount (ctx context.Context , key , min , max string ) * IntCmd
256256 ZIncrBy (ctx context.Context , key string , increment float64 , member string ) * FloatCmd
257+ ZInter (ctx context.Context , store * ZStore ) * StringSliceCmd
258+ ZInterWithScores (ctx context.Context , store * ZStore ) * ZSliceCmd
257259 ZInterStore (ctx context.Context , destination string , store * ZStore ) * IntCmd
258260 ZMScore (ctx context.Context , key string , members ... string ) * FloatSliceCmd
259261 ZPopMax (ctx context.Context , key string , count ... int64 ) * ZSliceCmd
@@ -1943,6 +1945,17 @@ type ZStore struct {
19431945 Aggregate string
19441946}
19451947
1948+ func (z * ZStore ) len () (n int ) {
1949+ n = len (z .Keys )
1950+ if len (z .Weights ) > 0 {
1951+ n += 1 + len (z .Weights )
1952+ }
1953+ if z .Aggregate != "" {
1954+ n += 2
1955+ }
1956+ return n
1957+ }
1958+
19461959// Redis `BZPOPMAX key [key ...] timeout` command.
19471960func (c cmdable ) BZPopMax (ctx context.Context , timeout time.Duration , keys ... string ) * ZWithKeyCmd {
19481961 args := make ([]interface {}, 1 + len (keys )+ 1 )
@@ -2088,7 +2101,7 @@ func (c cmdable) ZIncrBy(ctx context.Context, key string, increment float64, mem
20882101}
20892102
20902103func (c cmdable ) ZInterStore (ctx context.Context , destination string , store * ZStore ) * IntCmd {
2091- args := make ([]interface {}, 0 , 3 + len ( store .Keys ))
2104+ args := make ([]interface {}, 0 , 3 + store .len ( ))
20922105 args = append (args , "zinterstore" , destination , len (store .Keys ))
20932106 for _ , key := range store .Keys {
20942107 args = append (args , key )
@@ -2108,6 +2121,50 @@ func (c cmdable) ZInterStore(ctx context.Context, destination string, store *ZSt
21082121 return cmd
21092122}
21102123
2124+ func (c cmdable ) ZInter (ctx context.Context , store * ZStore ) * StringSliceCmd {
2125+ args := make ([]interface {}, 0 , 2 + store .len ())
2126+ args = append (args , "zinter" , len (store .Keys ))
2127+ for _ , key := range store .Keys {
2128+ args = append (args , key )
2129+ }
2130+ if len (store .Weights ) > 0 {
2131+ args = append (args , "weights" )
2132+ for _ , weights := range store .Weights {
2133+ args = append (args , weights )
2134+ }
2135+ }
2136+
2137+ if store .Aggregate != "" {
2138+ args = append (args , "aggregate" , store .Aggregate )
2139+ }
2140+ cmd := NewStringSliceCmd (ctx , args ... )
2141+ cmd .setFirstKeyPos (2 )
2142+ _ = c (ctx , cmd )
2143+ return cmd
2144+ }
2145+
2146+ func (c cmdable ) ZInterWithScores (ctx context.Context , store * ZStore ) * ZSliceCmd {
2147+ args := make ([]interface {}, 0 , 3 + store .len ())
2148+ args = append (args , "zinter" , len (store .Keys ))
2149+ for _ , key := range store .Keys {
2150+ args = append (args , key )
2151+ }
2152+ if len (store .Weights ) > 0 {
2153+ args = append (args , "weights" )
2154+ for _ , weights := range store .Weights {
2155+ args = append (args , weights )
2156+ }
2157+ }
2158+ if store .Aggregate != "" {
2159+ args = append (args , "aggregate" , store .Aggregate )
2160+ }
2161+ args = append (args , "withscores" )
2162+ cmd := NewZSliceCmd (ctx , args ... )
2163+ cmd .setFirstKeyPos (2 )
2164+ _ = c (ctx , cmd )
2165+ return cmd
2166+ }
2167+
21112168func (c cmdable ) ZMScore (ctx context.Context , key string , members ... string ) * FloatSliceCmd {
21122169 args := make ([]interface {}, 2 + len (members ))
21132170 args [0 ] = "zmscore"
@@ -2334,7 +2391,7 @@ func (c cmdable) ZScore(ctx context.Context, key, member string) *FloatCmd {
23342391}
23352392
23362393func (c cmdable ) ZUnionStore (ctx context.Context , dest string , store * ZStore ) * IntCmd {
2337- args := make ([]interface {}, 0 , 3 + len ( store .Keys ))
2394+ args := make ([]interface {}, 0 , 3 + store .len ( ))
23382395 args = append (args , "zunionstore" , dest , len (store .Keys ))
23392396 for _ , key := range store .Keys {
23402397 args = append (args , key )
0 commit comments