w3resource

Redis Sorted Sets: ZREM

Redis ZREM Command

Redis ZREM command is used to remove the specified members from the sorted set stored at key. The number which does not exist are ignored and an error is returned when key exists and does not hold a sorted set.

Here are some common uses and scenarios for the "ZREM" command:

  • Leaderboards: Remove players from a leaderboard based on certain criteria (e.g., inactive players).
  • Data Management: Manage and clean up data by removing irrelevant or outdated members from sorted sets.
  • Ranking Systems: Adjust rankings by removing members based on their scores or other attributes.
  • Event Handling: Remove events or messages from sorted sets after processing or expiration.
  • Performance Optimization: Optimize memory usage by removing unnecessary elements from sorted sets.

Syntax:

ZREM key member [member ...]

Available since

1.2.0.

Return Value

Integer, the number of members removed from the sorted set, not including non-existing members.

Return Value Type

Integer

Example: Redis ZREM

127.0.0.1:6379> ZADD mysales 1556 Samsung 2000 Nokia 1800 Micromax
(integer) 3
127.0.0.1:6379> ZADD mysales 2200 Sunsui 1800 MicroSoft 2500 LG
(integer) 3
127.0.0.1:6379> ZREVRANGE mysales 0 -1 WITHSCORES
 1) "LG"
 2) "2500"
 3) "Sunsui"
 4) "2200"
 5) "Nokia"
 6) "2000"
 7) "Micromax"
 8) "1800"
 9) "MicroSoft"
10) "1800"
11) "Samsung"
12) "1556"
127.0.0.1:6379> ZREM mysales Micromax LG Nokia
(integer) 3
127.0.0.1:6379> ZREVRANGE mysales 0 -1 WITHSCORES
1) "Sunsui"
2) "2200"
3) "MicroSoft"
4) "1800"
5) "Samsung"
6) "1556"

Previous: ZRANK
Next: ZREMRANGEBYLEX



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/redis/redis-zrem-key-member.php