Redis Sorted Sets: ZREMRANGEBYSCORE
Redis ZREMRANGEBYSCORE Command
Redis ZREMRANGEBYSCORE command is used to remove all elements in the sorted set stored at the key with a score between the minimum and maximum value.
min, max in the range of score. To delete all use -inf, + inf.
Here are some common uses and scenarios for the "ZREMRANGEBYSCORE" command:
- Score-Based Removal: Remove members from a sorted set within a specified score range.
- Leaderboards: Manage leaderboards by removing players with scores within a specific range.
- Data Management: Clean up and manage data by removing members based on their scores.
- Performance Optimization: Optimize memory usage by removing elements based on their scores in sorted sets.
- Data Integrity: Ensure data integrity by removing elements that fall within undesired score ranges.
Syntax
ZREMRANGEBYSCORE key min max
Available since
2.2.0.
Return Value
Integer reply, the number of elements removed.
Return Value Type
Integer
Example: Redis ZREMRANGEBYSCORE
127.0.0.1:6379> ZADD mycityset 80 Delhi 60 Mumbai 70 Hyderabad 50 Kolkata 65 Chennai (integer) 5 127.0.0.1:6379> ZRANGEBYSCORE mycityset -inf +inf WITHSCORES 1) "Kolkata" 2) "50" 3) "Mumbai" 4) "60" 5) "Chennai" 6) "65" 7) "Hyderabad" 8) "70" 9) "Delhi" 10) "80" 127.0.0.1:6379> ZREMRANGEBYSCORE mycityset -inf (70 (integer) 3 127.0.0.1:6379> ZRANGEBYSCORE mycityset -inf +inf WITHSCORES 1) "Hyderabad" 2) "70" 3) "Delhi" 4) "80" 127.0.0.1:6379> ZREMRANGEBYSCORE mycityset -inf 70 (integer) 1 127.0.0.1:6379> ZRANGEBYSCORE mycityset -inf +inf WITHSCORES 1) "Delhi" 2) "80"
Previous:
ZREMRANGEBYRANK
Next:
ZREVRANGE
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-zremrangebyscore-key-min-max.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics