ZPOPMIN
The ZPOPMIN
command in DiceDB is used to remove and return the members with the lowest scores from the sorted set data structure at the specified key. If a count is provided, it returns up to that number of members with the lowest scores, removing them from the set.
Syntax
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
key | The name of the sorted set. If it does not exist, an empty array is returned. | String | Yes |
count | The count argument specifies the number of members to return with the lowest scores. | Integer | No |
Return values
Condition | Return Value |
---|---|
If the key is of valid type and records are present | List of members including their scores |
If the key does not exist or if the sorted set is empty | (empty list or set) |
Behaviour
- The command first checks if the specified key exists.
- If the key does not exist, an empty array is returned.
- If the key exists but is not a sorted set, an error is returned.
- If the
count
argument is specified, up to that number of members with the lowest scores are returned and removed. - The returned array contains the members and their corresponding scores in the order of lowest to highest.
Errors
-
Wrong type of value or key
:- Error Message:
(error) WRONGTYPE Operation against a key holding the wrong kind of value
- Occurs when trying to use the command on a key that is not a sorted set.
- Error Message:
-
Invalid syntax or conflicting options
:- Error Message:
(error) ERROR wrong number of arguments for 'zpopmin' command
- Occurs when the command syntax is incorrect or missing required parameters.
- Error Message:
-
Non-integer value for
count“:- Error Message :
(error) ERR value is not an integer or out of range
- Occurs when the count argument passed to the command is not an integer.
- Error Message :
Examples
Basic Usage
Popping the member with the lowest score from an existing sorted set:
Non-Existing Key
Attempting to pop the member with the lowest score from a non-existent sorted set:
With count argumment
Popping multiple members with the lowest scores using the count argument:
Count Argument but Multiple Members Have the Same Score
Popping members when multiple members share the same score:
Negative Count Argument
Attempting to pop members using a negative count argument:
Floating-Point Scores
Popping members with floating-point scores:
Wrong number of arguments
Attempting to pop from a key that is not a sorted set:
Invalid Usage
Using an invalid (non-integer) count argument:
Wrong Type of Key
Attempting to pop from a key that is not a sorted set: