Redis ZREM – How to delete an element from a sorted set value in redis

5 years ago Lalit Bhagtani 0

In this tutorial, we will learn about how to delete one or more specified elements from a sorted set value stored at a key. For this we will use a COMMAND – ZREM in redis-cli. 

This command, deletes one or more specified elements from the sorted set stored at the specified key. Specified members that are not present in the sorted set are ignored. Error is returned, if key exist but value stored at the key is not of sorted set datatype. The syntax of redis ZREM command is as follows :- 

Syntax :-

redis host:post> ZREM <keyname> <element> [ element ]

Output :- 

- (integer) representing number of elements deleted from the sorted set, excluding non existing members.
- Error, if key exist and value stored at the key is not a sorted set.

Example :-

Redis ZREM

References :-

  1. ZREM Command Docs

That’s all for how to delete one or more specified elements from a sorted set value stored in redis datastore. If you liked it, please share your thoughts in comments section and share it with others too.