@@ -254,6 +254,8 @@ type Cmdable interface {
254
254
ZCount (ctx context.Context , key , min , max string ) * IntCmd
255
255
ZLexCount (ctx context.Context , key , min , max string ) * IntCmd
256
256
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
257
259
ZInterStore (ctx context.Context , destination string , store * ZStore ) * IntCmd
258
260
ZMScore (ctx context.Context , key string , members ... string ) * FloatSliceCmd
259
261
ZPopMax (ctx context.Context , key string , count ... int64 ) * ZSliceCmd
@@ -1943,6 +1945,17 @@ type ZStore struct {
1943
1945
Aggregate string
1944
1946
}
1945
1947
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
+
1946
1959
// Redis `BZPOPMAX key [key ...] timeout` command.
1947
1960
func (c cmdable ) BZPopMax (ctx context.Context , timeout time.Duration , keys ... string ) * ZWithKeyCmd {
1948
1961
args := make ([]interface {}, 1 + len (keys )+ 1 )
@@ -2088,7 +2101,7 @@ func (c cmdable) ZIncrBy(ctx context.Context, key string, increment float64, mem
2088
2101
}
2089
2102
2090
2103
func (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 ( ))
2092
2105
args = append (args , "zinterstore" , destination , len (store .Keys ))
2093
2106
for _ , key := range store .Keys {
2094
2107
args = append (args , key )
@@ -2108,6 +2121,50 @@ func (c cmdable) ZInterStore(ctx context.Context, destination string, store *ZSt
2108
2121
return cmd
2109
2122
}
2110
2123
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
+
2111
2168
func (c cmdable ) ZMScore (ctx context.Context , key string , members ... string ) * FloatSliceCmd {
2112
2169
args := make ([]interface {}, 2 + len (members ))
2113
2170
args [0 ] = "zmscore"
@@ -2334,7 +2391,7 @@ func (c cmdable) ZScore(ctx context.Context, key, member string) *FloatCmd {
2334
2391
}
2335
2392
2336
2393
func (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 ( ))
2338
2395
args = append (args , "zunionstore" , dest , len (store .Keys ))
2339
2396
for _ , key := range store .Keys {
2340
2397
args = append (args , key )
0 commit comments