Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: TJ Zhang <[email protected]>
  • Loading branch information
TJ Zhang committed Jan 30, 2025
1 parent 25c402e commit 2936629
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
3 changes: 0 additions & 3 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6931,9 +6931,6 @@ func (client *baseClient) ZInterWithScores(options *options.ZInterOptions) (map[
if err != nil {
return nil, err
}
// fmt.Println("--------------------------------")
// fmt.Println(args)
// fmt.Println("--------------------------------")
result, err := client.executeCommand(C.ZInter, args)
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion go/api/options/weight_aggregate_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ func (a Aggregate) ToArgs() []string {
return []string{AggregateKeyWord, string(a)}
}

// interface representing the keys or weighted keys
// This is a basic interface. Please use one of the following implementations:
// - KeyArray
// - WeightedKeys
type KeysOrWeightedKeys interface {
ToArgs() []string
}
Expand Down
1 change: 1 addition & 0 deletions go/api/options/zinter_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func NewZInterOptionsBuilder(keysOrWeightedKeys KeysOrWeightedKeys) *ZInterOptio
return &ZInterOptions{keysOrWeightedKeys: keysOrWeightedKeys}
}

// SetAggregate sets the aggregate method for the ZInter command.
func (options *ZInterOptions) SetAggregate(aggregate Aggregate) *ZInterOptions {
options.aggregate = aggregate
return options
Expand Down
22 changes: 10 additions & 12 deletions go/integTest/shared_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7615,10 +7615,8 @@ func (suite *GlideTestSuite) TestBitFieldRO_MultipleGets() {
}

func (suite *GlideTestSuite) TestZInter() {
suite.SkipIfServerVersionLowerThanBy("6.2.0")
suite.runWithDefaultClients(func(client api.BaseClient) {
if suite.serverVersion < "6.2.0" {
suite.T().Skip("This feature was added in version 6.2.0")
}
key1 := "{key}-" + uuid.New().String()
key2 := "{key}-" + uuid.New().String()
key3 := "{key}-" + uuid.New().String()
Expand All @@ -7633,44 +7631,44 @@ func (suite *GlideTestSuite) TestZInter() {

// Add members to sorted sets
res, err := client.ZAdd(key1, memberScoreMap1)
assert.Nil(suite.T(), err)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), int64(2), res)

res, err = client.ZAdd(key2, memberScoreMap2)
assert.Nil(suite.T(), err)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), int64(2), res)

// intersection results are aggregated by the max score of elements
zinterResult, err := client.ZInter(options.KeyArray{Keys: []string{key1, key2}})
assert.Nil(suite.T(), err)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), []string{"two"}, zinterResult)

// intersection with scores
zinterWithScoresResult, err := client.ZInterWithScores(
options.NewZInterOptionsBuilder(options.KeyArray{Keys: []string{key1, key2}}).SetAggregate(options.AggregateSum),
)
assert.Nil(suite.T(), err)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), map[string]float64{"two": 5.5}, zinterWithScoresResult)

// intersect results with max aggregate
zinterWithMaxAggregateResult, err := client.ZInterWithScores(
options.NewZInterOptionsBuilder(options.KeyArray{Keys: []string{key1, key2}}).SetAggregate(options.AggregateMax),
)
assert.Nil(suite.T(), err)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), map[string]float64{"two": 3.5}, zinterWithMaxAggregateResult)

// intersect results with min aggregate
zinterWithMinAggregateResult, err := client.ZInterWithScores(
options.NewZInterOptionsBuilder(options.KeyArray{Keys: []string{key1, key2}}).SetAggregate(options.AggregateMin),
)
assert.Nil(suite.T(), err)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), map[string]float64{"two": 2.0}, zinterWithMinAggregateResult)

// intersect results with sum aggregate
zinterWithSumAggregateResult, err := client.ZInterWithScores(
options.NewZInterOptionsBuilder(options.KeyArray{Keys: []string{key1, key2}}).SetAggregate(options.AggregateSum),
)
assert.Nil(suite.T(), err)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), map[string]float64{"two": 5.5}, zinterWithSumAggregateResult)

// Scores are multiplied by a 2.0 weight for key1 and key2 during aggregation
Expand All @@ -7684,14 +7682,14 @@ func (suite *GlideTestSuite) TestZInter() {
},
).SetAggregate(options.AggregateSum),
)
assert.Nil(suite.T(), err)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), map[string]float64{"two": 11.0}, zinterWithWeightedKeysResult)

// non-existent key - empty intersection
zinterWithNonExistentKeyResult, err := client.ZInterWithScores(
options.NewZInterOptionsBuilder(options.KeyArray{Keys: []string{key1, key3}}).SetAggregate(options.AggregateSum),
)
assert.Nil(suite.T(), err)
assert.NoError(suite.T(), err)
assert.Empty(suite.T(), zinterWithNonExistentKeyResult)

// empty key list - request error
Expand Down

0 comments on commit 2936629

Please sign in to comment.