Skip to content

Commit

Permalink
add documentation for BZPopMin
Browse files Browse the repository at this point in the history
Signed-off-by: jbrinkman <[email protected]>
  • Loading branch information
jbrinkman committed Dec 24, 2024
1 parent 22e8992 commit 51d0ed3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
16 changes: 2 additions & 14 deletions go/api/response_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,28 +408,16 @@ 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 {
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"}
}
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
}
Expand Down
27 changes: 27 additions & 0 deletions go/api/sorted_set_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 51d0ed3

Please sign in to comment.