From 259eb61b421fcdedf1a66e78cc6933c575263cf9 Mon Sep 17 00:00:00 2001 From: jbrinkman Date: Fri, 20 Dec 2024 15:14:14 -0500 Subject: [PATCH 01/10] GO: Add BZPopMin command Signed-off-by: jbrinkman --- go/api/base_client.go | 9 ++++++ go/api/sorted_set_commands.go | 3 ++ go/integTest/shared_commands_test.go | 41 ++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/go/api/base_client.go b/go/api/base_client.go index 99cab3608d..469b393013 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -1441,3 +1441,12 @@ func (client *baseClient) ZCard(key string) (Result[int64], error) { return handleLongResponse(result) } + +func (client *baseClient) BZPopMin(keys []string, timeoutSecs float64) ([]Result[string], error) { + result, err := client.executeCommand(C.BZPopMin, append(keys, utils.FloatToString(timeoutSecs))) + if err != nil { + return nil, err + } + + return handleStringArrayOrNullResponse(result) +} diff --git a/go/api/sorted_set_commands.go b/go/api/sorted_set_commands.go index 4159acabe1..3312388ecf 100644 --- a/go/api/sorted_set_commands.go +++ b/go/api/sorted_set_commands.go @@ -232,4 +232,7 @@ type SortedSetCommands interface { // // [valkey.io]: https://valkey.io/commands/zcard/ ZCard(key string) (Result[int64], error) + + // [valkey bzpopmin]: https://valkey.io/commands/bzpopmin/ + BZPopMin(keys []string, timeoutSecs float64) ([]Result[string], error) } diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index eefd38e9b0..f3594cf64a 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -4136,6 +4136,47 @@ func (suite *GlideTestSuite) TestZincrBy() { assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &api.RequestError{}, err) }) + +func (suite *GlideTestSuite) TestBZPopMin() { + suite.runWithDefaultClients(func(client api.BaseClient) { + key1 := "{listKey}-1-" + uuid.NewString() + // key2 := "{listKey}-2-" + uuid.NewString() + + // Add elements to key1 + zaddResult1, err := client.ZAdd(key1, map[string]float64{"a": 1.0, "b": 1.5}) + assert.Nil(suite.T(), err) + assert.Equal(suite.T(), int64(2), zaddResult1.Value()) + + // Add elements to key2 + // zaddResult2, err := client.ZAdd(key2, map[string]float64{"c": 2.0}) + // assert.Nil(suite.T(), err) + // assert.Equal(suite.T(), int64(1), zaddResult2.Value()) + + // // Pop minimum element from key1 and key2 + // bzpopminResult1, err := client.BZPopMin([]string{key1, key2}, 500*time.Millisecond) + // assert.NoError(suite.T(), err) + // assert.Equal(suite.T() []interface{}{key1, "a", 1.0}, bzpopminResult1) + + // // Attempt to pop from non-existent key3 + // bzpopminResult2, err := client.BZPopMin([]string{key3}, 1*time.Second) + // assert.NoError(suite.T() err) + // assert.Nil(suite.T() bzpopminResult2) + + // // Pop minimum element from key2 + // bzpopminResult3, err := client.BZPopMin([]string{key3, key2}, 500*time.Millisecond) + // assert.NoError(suite.T() err) + // assert.Equal(suite.T() []interface{}{key2, "c", 2.0}, bzpopminResult3) + + // // Set key3 to a non-sorted set value + // setResult, err := client.Set(key3, "value") + // assert.NoError(suite.T() err) + // assert.Equal(suite.T() "OK", setResult) + + // // Attempt to pop from key3 which is not a sorted set + // _, err = client.BZPopMin([]string{key3}, 500*time.Millisecond) + // assert.Error(suite.T() err) + // assert.IsType(suite.T() RequestException{}, err) + }) } func (suite *GlideTestSuite) TestZPopMin() { From a724aca2037a58837346f85a5cd82db30bbd1b56 Mon Sep 17 00:00:00 2001 From: jbrinkman Date: Tue, 24 Dec 2024 10:42:01 -0500 Subject: [PATCH 02/10] add response handler for BZPopMin Signed-off-by: jbrinkman --- go/api/base_client.go | 6 +-- go/api/response_handlers.go | 30 +++++++++++++++ go/api/response_types.go | 13 +++++++ go/api/sorted_set_commands.go | 4 +- go/integTest/shared_commands_test.go | 56 ++++++++++++++-------------- 5 files changed, 77 insertions(+), 32 deletions(-) diff --git a/go/api/base_client.go b/go/api/base_client.go index 469b393013..81f965d537 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -1442,11 +1442,11 @@ func (client *baseClient) ZCard(key string) (Result[int64], error) { return handleLongResponse(result) } -func (client *baseClient) BZPopMin(keys []string, timeoutSecs float64) ([]Result[string], error) { +func (client *baseClient) BZPopMin(keys []string, timeoutSecs float64) (Result[KeyWithMemberAndScore], error) { result, err := client.executeCommand(C.BZPopMin, append(keys, utils.FloatToString(timeoutSecs))) if err != nil { - return nil, err + return CreateNilKeyWithMemberAndScoreResult(), err } - return handleStringArrayOrNullResponse(result) + return handleKeyWithMemberAndScoreResponse(result) } diff --git a/go/api/response_handlers.go b/go/api/response_handlers.go index dd4c2d1f24..4ccb5d9a53 100644 --- a/go/api/response_handlers.go +++ b/go/api/response_handlers.go @@ -397,6 +397,36 @@ func handleStringSetResponse(response *C.struct_CommandResponse) (map[Result[str return slice, nil } +func describe(i interface{}) { + fmt.Printf("(%v, %T)\n", i, i) +} + +func handleKeyWithMemberAndScoreResponse(response *C.struct_CommandResponse) (Result[KeyWithMemberAndScore], error) { + defer C.free_command_response(response) + + describe(response) + typeErr := checkResponseType(response, C.Array, false) + if typeErr != nil { + return CreateNilKeyWithMemberAndScoreResult(), typeErr + } + + return CreateNilKeyWithMemberAndScoreResult(), nil + // m := make(map[Result[string]]Result[float64], response.array_value_len) + // for _, v := range unsafe.Slice(response.array_value, response.array_value_len) { + // key, err := convertCharArrayToString(v.map_key, true) + // if err != nil { + // return nil, err + // } + // value, err := handleDoubleResponse(v.map_value) + // if err != nil { + // return nil, err + // } + // m[key] = value + // } + + // return m, nil +} + func handleScanResponse( response *C.struct_CommandResponse, ) (Result[string], []Result[string], error) { diff --git a/go/api/response_types.go b/go/api/response_types.go index 3146032b04..3338f51c05 100644 --- a/go/api/response_types.go +++ b/go/api/response_types.go @@ -7,6 +7,11 @@ type Result[T any] struct { isNil bool } +type KeyWithMemberAndScore struct { + Key, Member string + Score float64 +} + func (result Result[T]) IsNil() bool { return result.isNil } @@ -47,6 +52,14 @@ func CreateNilBoolResult() Result[bool] { return Result[bool]{val: false, isNil: true} } +func CreateKeyWithMemberAndScoreResult(kmsVal KeyWithMemberAndScore) Result[KeyWithMemberAndScore] { + return Result[KeyWithMemberAndScore]{val: kmsVal, isNil: false} +} + +func CreateNilKeyWithMemberAndScoreResult() Result[KeyWithMemberAndScore] { + return Result[KeyWithMemberAndScore]{val: KeyWithMemberAndScore{"", "", 0.0}, isNil: true} +} + // Enum to distinguish value types stored in `ClusterValue` type ValueType int diff --git a/go/api/sorted_set_commands.go b/go/api/sorted_set_commands.go index 3312388ecf..d98c0cafae 100644 --- a/go/api/sorted_set_commands.go +++ b/go/api/sorted_set_commands.go @@ -233,6 +233,6 @@ type SortedSetCommands interface { // [valkey.io]: https://valkey.io/commands/zcard/ ZCard(key string) (Result[int64], error) - // [valkey bzpopmin]: https://valkey.io/commands/bzpopmin/ - BZPopMin(keys []string, timeoutSecs float64) ([]Result[string], error) + // [valkey.io]: https://valkey.io/commands/bzpopmin/ + BZPopMin(keys []string, timeoutSecs float64) (Result[KeyWithMemberAndScore], error) } diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index f3594cf64a..2a57026ea6 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -4136,11 +4136,13 @@ func (suite *GlideTestSuite) TestZincrBy() { assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &api.RequestError{}, err) }) +} func (suite *GlideTestSuite) TestBZPopMin() { suite.runWithDefaultClients(func(client api.BaseClient) { key1 := "{listKey}-1-" + uuid.NewString() - // key2 := "{listKey}-2-" + uuid.NewString() + key2 := "{listKey}-2-" + uuid.NewString() + key3 := "{listKey}-2-" + uuid.NewString() // Add elements to key1 zaddResult1, err := client.ZAdd(key1, map[string]float64{"a": 1.0, "b": 1.5}) @@ -4148,34 +4150,34 @@ func (suite *GlideTestSuite) TestBZPopMin() { assert.Equal(suite.T(), int64(2), zaddResult1.Value()) // Add elements to key2 - // zaddResult2, err := client.ZAdd(key2, map[string]float64{"c": 2.0}) - // assert.Nil(suite.T(), err) - // assert.Equal(suite.T(), int64(1), zaddResult2.Value()) - - // // Pop minimum element from key1 and key2 - // bzpopminResult1, err := client.BZPopMin([]string{key1, key2}, 500*time.Millisecond) - // assert.NoError(suite.T(), err) - // assert.Equal(suite.T() []interface{}{key1, "a", 1.0}, bzpopminResult1) - - // // Attempt to pop from non-existent key3 - // bzpopminResult2, err := client.BZPopMin([]string{key3}, 1*time.Second) - // assert.NoError(suite.T() err) - // assert.Nil(suite.T() bzpopminResult2) - - // // Pop minimum element from key2 - // bzpopminResult3, err := client.BZPopMin([]string{key3, key2}, 500*time.Millisecond) - // assert.NoError(suite.T() err) - // assert.Equal(suite.T() []interface{}{key2, "c", 2.0}, bzpopminResult3) - - // // Set key3 to a non-sorted set value - // setResult, err := client.Set(key3, "value") - // assert.NoError(suite.T() err) - // assert.Equal(suite.T() "OK", setResult) + zaddResult2, err := client.ZAdd(key2, map[string]float64{"c": 2.0}) + assert.Nil(suite.T(), err) + assert.Equal(suite.T(), int64(1), zaddResult2.Value()) + + // Pop minimum element from key1 and key2 + bzpopminResult1, err := client.BZPopMin([]string{key1, key2}, float64(500*time.Millisecond)) + assert.Nil(suite.T(), err) + assert.Equal(suite.T(), []interface{}{key1, "a", 1.0}, bzpopminResult1) + + // Attempt to pop from non-existent key3 + bzpopminResult2, err := client.BZPopMin([]string{key3}, float64(1*time.Second)) + assert.Nil(suite.T(), err) + assert.Nil(suite.T(), bzpopminResult2) + + // Pop minimum element from key2 + bzpopminResult3, err := client.BZPopMin([]string{key3, key2}, float64(500*time.Millisecond)) + assert.Nil(suite.T(), err) + assert.Equal(suite.T(), []interface{}{key2, "c", 2.0}, bzpopminResult3) + + // Set key3 to a non-sorted set value + setResult, err := client.Set(key3, "value") + assert.Nil(suite.T(), err) + assert.Equal(suite.T(), "OK", setResult) // // Attempt to pop from key3 which is not a sorted set - // _, err = client.BZPopMin([]string{key3}, 500*time.Millisecond) - // assert.Error(suite.T() err) - // assert.IsType(suite.T() RequestException{}, err) + // _, err = client.BZPopMin([]string{key3}, float64(500*time.Millisecond)) + // assert.Error(suite.T(), err) + // assert.IsType(suite.T(), RequestException{}, err) }) } From 64d2d2b53595039dc120066d46ea2bf16383e456 Mon Sep 17 00:00:00 2001 From: jbrinkman Date: Tue, 24 Dec 2024 15:27:56 -0500 Subject: [PATCH 03/10] cleanup response handler for BZPopMin Signed-off-by: jbrinkman --- go/api/response_handlers.go | 49 ++++++++++++++++------------ go/integTest/shared_commands_test.go | 23 ++++++------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/go/api/response_handlers.go b/go/api/response_handlers.go index 4ccb5d9a53..d2e2eea6a3 100644 --- a/go/api/response_handlers.go +++ b/go/api/response_handlers.go @@ -397,34 +397,41 @@ func handleStringSetResponse(response *C.struct_CommandResponse) (map[Result[str return slice, nil } -func describe(i interface{}) { - fmt.Printf("(%v, %T)\n", i, i) -} - func handleKeyWithMemberAndScoreResponse(response *C.struct_CommandResponse) (Result[KeyWithMemberAndScore], error) { defer C.free_command_response(response) - describe(response) - typeErr := checkResponseType(response, C.Array, false) + if response == nil || response.response_type == uint32(C.Null) { + return CreateNilKeyWithMemberAndScoreResult(), nil + } + + typeErr := checkResponseType(response, C.Array, true) if typeErr != nil { return CreateNilKeyWithMemberAndScoreResult(), typeErr } + if response.array_value_len != 3 { + return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected number of elements in response"} + } - return CreateNilKeyWithMemberAndScoreResult(), nil - // m := make(map[Result[string]]Result[float64], response.array_value_len) - // for _, v := range unsafe.Slice(response.array_value, response.array_value_len) { - // key, err := convertCharArrayToString(v.map_key, true) - // if err != nil { - // return nil, err - // } - // value, err := handleDoubleResponse(v.map_value) - // if err != nil { - // return nil, err - // } - // m[key] = value - // } - - // return m, nil + slice, err := parseArray(response) + if err != nil { + return CreateNilKeyWithMemberAndScoreResult(), err + } + + arr := slice.([]interface{}) + key, ok := arr[0].(string) + if !ok { + return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected type of key"} + } + member, ok := arr[1].(string) + if !ok { + return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected type of member"} + } + score := arr[2].(float64) + if !ok { + return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected type of score"} + } + kms := KeyWithMemberAndScore{key, member, score} + return CreateKeyWithMemberAndScoreResult(kms), nil } func handleScanResponse( diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index 2a57026ea6..3ae5059ee9 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -4155,29 +4155,30 @@ func (suite *GlideTestSuite) TestBZPopMin() { assert.Equal(suite.T(), int64(1), zaddResult2.Value()) // Pop minimum element from key1 and key2 - bzpopminResult1, err := client.BZPopMin([]string{key1, key2}, float64(500*time.Millisecond)) + bzpopminResult1, err := client.BZPopMin([]string{key1, key2}, float64(.5)) assert.Nil(suite.T(), err) - assert.Equal(suite.T(), []interface{}{key1, "a", 1.0}, bzpopminResult1) + assert.Equal(suite.T(), api.KeyWithMemberAndScore{Key: key1, Member: "a", Score: 1.0}, bzpopminResult1.Value()) // Attempt to pop from non-existent key3 - bzpopminResult2, err := client.BZPopMin([]string{key3}, float64(1*time.Second)) + bzpopminResult2, err := client.BZPopMin([]string{key3}, float64(1)) assert.Nil(suite.T(), err) - assert.Nil(suite.T(), bzpopminResult2) + assert.True(suite.T(), bzpopminResult2.IsNil()) // Pop minimum element from key2 - bzpopminResult3, err := client.BZPopMin([]string{key3, key2}, float64(500*time.Millisecond)) + bzpopminResult3, err := client.BZPopMin([]string{key3, key2}, float64(.5)) assert.Nil(suite.T(), err) - assert.Equal(suite.T(), []interface{}{key2, "c", 2.0}, bzpopminResult3) + assert.Equal(suite.T(), api.KeyWithMemberAndScore{Key: key2, Member: "c", Score: 2.0}, bzpopminResult3.Value()) // Set key3 to a non-sorted set value setResult, err := client.Set(key3, "value") assert.Nil(suite.T(), err) - assert.Equal(suite.T(), "OK", setResult) + assert.Equal(suite.T(), "OK", setResult.Value()) - // // Attempt to pop from key3 which is not a sorted set - // _, err = client.BZPopMin([]string{key3}, float64(500*time.Millisecond)) - // assert.Error(suite.T(), err) - // assert.IsType(suite.T(), RequestException{}, err) + // Attempt to pop from key3 which is not a sorted set + _, err = client.BZPopMin([]string{key3}, float64(.5)) + if assert.Error(suite.T(), err) { + assert.IsType(suite.T(), &api.RequestError{}, err) + } }) } From 8fbabdaddb0a14d90e01951866a0ae28cdabb40b Mon Sep 17 00:00:00 2001 From: jbrinkman Date: Tue, 24 Dec 2024 17:46:28 -0500 Subject: [PATCH 04/10] add documentation for BZPopMin Signed-off-by: jbrinkman --- go/api/response_handlers.go | 16 ++-------------- go/api/sorted_set_commands.go | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/go/api/response_handlers.go b/go/api/response_handlers.go index d2e2eea6a3..a8e22a7edc 100644 --- a/go/api/response_handlers.go +++ b/go/api/response_handlers.go @@ -408,9 +408,6 @@ func handleKeyWithMemberAndScoreResponse(response *C.struct_CommandResponse) (Re if typeErr != nil { return CreateNilKeyWithMemberAndScoreResult(), typeErr } - if response.array_value_len != 3 { - return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected number of elements in response"} - } slice, err := parseArray(response) if err != nil { @@ -418,18 +415,9 @@ func handleKeyWithMemberAndScoreResponse(response *C.struct_CommandResponse) (Re } arr := slice.([]interface{}) - key, ok := arr[0].(string) - if !ok { - return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected type of key"} - } - member, ok := arr[1].(string) - if !ok { - return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected type of member"} - } + key := arr[0].(string) + member := arr[1].(string) score := arr[2].(float64) - if !ok { - return CreateNilKeyWithMemberAndScoreResult(), &RequestError{"Unexpected type of score"} - } kms := KeyWithMemberAndScore{key, member, score} return CreateKeyWithMemberAndScoreResult(kms), nil } diff --git a/go/api/sorted_set_commands.go b/go/api/sorted_set_commands.go index d98c0cafae..2b21ba01cf 100644 --- a/go/api/sorted_set_commands.go +++ b/go/api/sorted_set_commands.go @@ -233,6 +233,33 @@ type SortedSetCommands interface { // [valkey.io]: https://valkey.io/commands/zcard/ ZCard(key string) (Result[int64], error) + // Blocks the connection until it removes and returns a member with the lowest score from the + // first non-empty sorted set, with the given `keys`` being checked in the order they + // are provided. + // `BZPOPMIN` is the blocking variant of `ZPOPMIN``. + // + // Note: + // - When in cluster mode, all `keys` must map to the same hash slot. + // - `BZPOPMIN` is a client blocking command, see [Blocking Commands] for more details and best practices. + // + // see [valkey.io] for more details. + // + // Parameters: + // keys - The keys of the sorted sets. + // timeout - The number of seconds to wait for a blocking operation to complete. A value of + // `0` will block indefinitely. + // + // Return value: + // A `KeyWithMemberAndScore` struct containing the key where the member was popped out, the member + // itself, and the member score. If no member could be popped and the `timeout` expired, returns `null`. + // + // example + // zaddResult1, err := client.ZAdd(key1, map[string]float64{"a": 1.0, "b": 1.5}) + // zaddResult2, err := client.ZAdd(key2, map[string]float64{"c": 2.0}) + // result, err := client.BZPopMin([]string{key1, key2}, float64(.5)) + // fmt.Println(res.Value()) // Output: {key: key1 member:a, score:1} + // // [valkey.io]: https://valkey.io/commands/bzpopmin/ + // [blocking commands]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands BZPopMin(keys []string, timeoutSecs float64) (Result[KeyWithMemberAndScore], error) } From 723f46ecafd9479633afa9bac9a3402258861689 Mon Sep 17 00:00:00 2001 From: jbrinkman Date: Tue, 24 Dec 2024 17:49:25 -0500 Subject: [PATCH 05/10] update changelog for BZPopMin Signed-off-by: jbrinkman --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c7585a2f8..2603b0db20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ #### Changes + * Java, Node, Python: Add transaction commands for JSON module ([#2862](https://github.com/valkey-io/valkey-glide/pull/2862)) * Go: Add HINCRBY command ([#2847](https://github.com/valkey-io/valkey-glide/pull/2847)) * Go: Add HINCRBYFLOAT command ([#2846](https://github.com/valkey-io/valkey-glide/pull/2846)) @@ -13,6 +14,7 @@ * Go: Add `ZPopMin` and `ZPopMax` ([#2850](https://github.com/valkey-io/valkey-glide/pull/2850)) * Java: Add binary version of `ZRANK WITHSCORE` ([#2896](https://github.com/valkey-io/valkey-glide/pull/2896)) * Go: Add `ZCARD` ([#2838](https://github.com/valkey-io/valkey-glide/pull/2838)) +* Go: Add `BZPopMin` ([#2849](https://github.com/valkey-io/valkey-glide/pull/2849)) #### Breaking Changes From ec2a3c0547a05ccf71c1b7066c89d6fb15c9c540 Mon Sep 17 00:00:00 2001 From: Joseph Brinkman Date: Mon, 6 Jan 2025 08:31:35 -0500 Subject: [PATCH 06/10] Update go/api/sorted_set_commands.go Co-authored-by: Yury-Fridlyand Signed-off-by: Joseph Brinkman Signed-off-by: jbrinkman --- go/api/sorted_set_commands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/api/sorted_set_commands.go b/go/api/sorted_set_commands.go index 2b21ba01cf..5209bd6b7c 100644 --- a/go/api/sorted_set_commands.go +++ b/go/api/sorted_set_commands.go @@ -234,9 +234,9 @@ type SortedSetCommands interface { ZCard(key string) (Result[int64], error) // Blocks the connection until it removes and returns a member with the lowest score from the - // first non-empty sorted set, with the given `keys`` being checked in the order they + // first non-empty sorted set, with the given `keys` being checked in the order they // are provided. - // `BZPOPMIN` is the blocking variant of `ZPOPMIN``. + // `BZPOPMIN` is the blocking variant of `ZPOPMIN`. // // Note: // - When in cluster mode, all `keys` must map to the same hash slot. From cf34941fbb6ef2cbe0f675f6973290e2963bd016 Mon Sep 17 00:00:00 2001 From: Joseph Brinkman Date: Mon, 6 Jan 2025 08:32:06 -0500 Subject: [PATCH 07/10] Update go/api/response_handlers.go Co-authored-by: prateek-kumar-improving Signed-off-by: Joseph Brinkman Signed-off-by: jbrinkman --- go/api/response_handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/api/response_handlers.go b/go/api/response_handlers.go index a8e22a7edc..892ace82a9 100644 --- a/go/api/response_handlers.go +++ b/go/api/response_handlers.go @@ -419,7 +419,7 @@ func handleKeyWithMemberAndScoreResponse(response *C.struct_CommandResponse) (Re member := arr[1].(string) score := arr[2].(float64) kms := KeyWithMemberAndScore{key, member, score} - return CreateKeyWithMemberAndScoreResult(kms), nil + return CreateKeyWithMemberAndScoreResult(KeyWithMemberAndScore{arr[0].(string), arr[1].(string), arr[2].(float64)}), nil } func handleScanResponse( From 5caa2558ca63d15901563c0cdd1e85e9eb64be68 Mon Sep 17 00:00:00 2001 From: Joseph Brinkman Date: Mon, 6 Jan 2025 08:32:21 -0500 Subject: [PATCH 08/10] Update go/api/sorted_set_commands.go Co-authored-by: Yury-Fridlyand Signed-off-by: Joseph Brinkman Signed-off-by: jbrinkman --- go/api/sorted_set_commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/api/sorted_set_commands.go b/go/api/sorted_set_commands.go index 5209bd6b7c..24f7e199be 100644 --- a/go/api/sorted_set_commands.go +++ b/go/api/sorted_set_commands.go @@ -251,7 +251,7 @@ type SortedSetCommands interface { // // Return value: // A `KeyWithMemberAndScore` struct containing the key where the member was popped out, the member - // itself, and the member score. If no member could be popped and the `timeout` expired, returns `null`. + // itself, and the member score. If no member could be popped and the `timeout` expired, returns `nil`. // // example // zaddResult1, err := client.ZAdd(key1, map[string]float64{"a": 1.0, "b": 1.5}) From 55648a73eb8a5d7eb9993f92f84f01f779be964d Mon Sep 17 00:00:00 2001 From: Joseph Brinkman Date: Mon, 6 Jan 2025 08:32:37 -0500 Subject: [PATCH 09/10] Update go/api/sorted_set_commands.go Co-authored-by: Yury-Fridlyand Signed-off-by: Joseph Brinkman Signed-off-by: jbrinkman --- go/api/sorted_set_commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/api/sorted_set_commands.go b/go/api/sorted_set_commands.go index 24f7e199be..4b63b70091 100644 --- a/go/api/sorted_set_commands.go +++ b/go/api/sorted_set_commands.go @@ -242,7 +242,7 @@ type SortedSetCommands interface { // - When in cluster mode, all `keys` must map to the same hash slot. // - `BZPOPMIN` is a client blocking command, see [Blocking Commands] for more details and best practices. // - // see [valkey.io] for more details. + // See [valkey.io] for more details. // // Parameters: // keys - The keys of the sorted sets. From 1f10da5612f501be4ed552f6518ee7bfd8a692ea Mon Sep 17 00:00:00 2001 From: jbrinkman Date: Mon, 6 Jan 2025 09:44:08 -0500 Subject: [PATCH 10/10] apply code review formatting feedback Signed-off-by: jbrinkman --- go/api/response_handlers.go | 3 +-- go/api/response_types.go | 7 +++++-- go/integTest/shared_commands_test.go | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/go/api/response_handlers.go b/go/api/response_handlers.go index 892ace82a9..4a5056c0c6 100644 --- a/go/api/response_handlers.go +++ b/go/api/response_handlers.go @@ -418,8 +418,7 @@ func handleKeyWithMemberAndScoreResponse(response *C.struct_CommandResponse) (Re key := arr[0].(string) member := arr[1].(string) score := arr[2].(float64) - kms := KeyWithMemberAndScore{key, member, score} - return CreateKeyWithMemberAndScoreResult(KeyWithMemberAndScore{arr[0].(string), arr[1].(string), arr[2].(float64)}), nil + return CreateKeyWithMemberAndScoreResult(KeyWithMemberAndScore{key, member, score}), nil } func handleScanResponse( diff --git a/go/api/response_types.go b/go/api/response_types.go index 3338f51c05..6172c4ff2b 100644 --- a/go/api/response_types.go +++ b/go/api/response_types.go @@ -7,9 +7,12 @@ type Result[T any] struct { isNil bool } +// KeyWithMemberAndScore is used by BZPOPMIN/BZPOPMAX, which return an object consisting of the key of the sorted set that was +// popped, the popped member, and its score. type KeyWithMemberAndScore struct { - Key, Member string - Score float64 + Key string + Member string + Score float64 } func (result Result[T]) IsNil() bool { diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index 3ae5059ee9..9abe3714cb 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -4140,9 +4140,9 @@ func (suite *GlideTestSuite) TestZincrBy() { func (suite *GlideTestSuite) TestBZPopMin() { suite.runWithDefaultClients(func(client api.BaseClient) { - key1 := "{listKey}-1-" + uuid.NewString() - key2 := "{listKey}-2-" + uuid.NewString() - key3 := "{listKey}-2-" + uuid.NewString() + key1 := "{zset}-1-" + uuid.NewString() + key2 := "{zset}-2-" + uuid.NewString() + key3 := "{zset}-2-" + uuid.NewString() // Add elements to key1 zaddResult1, err := client.ZAdd(key1, map[string]float64{"a": 1.0, "b": 1.5})