Trim redis sorted sets to a max number
If you have a leaderboard or just want to save a specific number of the highest scored sets in a sorted set, use ZREMRANGEBYRANK. The example below will only keep the top 100 highest scored items:
ZREMRANGEBYRANK key 0 -100
Written by Arthur Chang
Related protips
1 Response
Off by one; to keep the top 100 you must do:
ZREMRANGEBYRANK key 0 -101</code>
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Redis
Authors
Related Tags
#redis
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#