From 2936629aaa9e249cd95c7b9936b84c4b26166e81 Mon Sep 17 00:00:00 2001 From: TJ Zhang Date: Thu, 30 Jan 2025 12:31:54 -0800 Subject: [PATCH] address comments Signed-off-by: TJ Zhang --- go/api/base_client.go | 3 --- go/api/options/weight_aggregate_options.go | 4 +++- go/api/options/zinter_options.go | 1 + go/integTest/shared_commands_test.go | 22 ++++++++++------------ 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/go/api/base_client.go b/go/api/base_client.go index 0df1d7cda2..2a464d4350 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -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 diff --git a/go/api/options/weight_aggregate_options.go b/go/api/options/weight_aggregate_options.go index ead73584fe..400150cc57 100644 --- a/go/api/options/weight_aggregate_options.go +++ b/go/api/options/weight_aggregate_options.go @@ -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 } diff --git a/go/api/options/zinter_options.go b/go/api/options/zinter_options.go index 6f710d47ed..845cdb5150 100644 --- a/go/api/options/zinter_options.go +++ b/go/api/options/zinter_options.go @@ -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 diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index cb2bbb92cf..401eca39ff 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -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() @@ -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 @@ -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