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 2bdc6f7502..bd6922482f 100644 --- a/go/api/sorted_set_commands.go +++ b/go/api/sorted_set_commands.go @@ -193,6 +193,33 @@ type SortedSetCommands interface { // [valkey.io]: https://valkey.io/commands/zpopmin/ ZPopMaxWithCount(key string, count int64) (map[Result[string]]Result[float64], 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) }