In this tutorial, we will learn about how to get the score of an element of the sorted set value stored at a key. For this we will use a Redis ZSCORE command.
The ZSCORE command is used to return the score of a specified element of the sorted set value stored at the specified key. Nil is returned, when element does not exist in the sorted set or key does not exist. Error is returned, when key exist but value stored at the key is not of sorted set datatype. The syntax of redis ZSCORE command is as follows :-
Syntax :-
redis host:post> ZSCORE <keyname> <element>
Output :-
- (string) reply, representing score of an element stored in the sorted set. - (nil), if element does not exist in the sorted set or if key does not exist. - Error, if key exist and value stored at the key is not a sorted set.
Example :-
References :-
- ZSCORE Command Docs
That’s all for how to get the score of an element of the sorted set value stored in redis datastore. If you liked it, please share your thoughts in comments section and share it with others too.