Storing Sorted Set in Redis: Utility Commands

Learn about some utility commands for sorted sets in Redis.

ZREM command

The ZREM command is used to remove a member from the sorted set. The syntax of this command is:

ZREM key value

ZRANK command

The ZRANK command is used to find the index of an element in the sorted set. If the rank of an element is 0, then its score is the lowest. The syntax of this command is:

ZRANK key member

Please note that the index starts at 0. In the example below, we are fetching the index of Canada in our set.

ZREVRANK command

The ZREVRANK command is used to find the rank from the reverse. If the rank of an element is 0, then the score is the highest. The syntax of this command is:

ZREVRANK key member

ZSCORE command

To get the score of an element, use the ZSCORE command. The syntax of this command is:

ZSCORE key member

Get hands-on with 1200+ tech skills courses.