I'm using redis lists and pushing to new items to a list. The problem is I really only need the most recent 10 items in a list.
I'm using lpush
to add items to a list and lrange
to get the most recent 10.
Is there anyway to drop items after a certain number? I'll end up with lists that may have 1,000's of items and can cause performance issues with latency.
Thank you!
Redis reads lists from left to right, and you can add new list elements to the head of a list (the “left” end) with the lpush command or the tail (the “right” end) with rpush . You can also use lpush or rpush to create a new list: lpush key value.
Delete the key, and that will clear all items. Not having the list at all is similar to not having any items in it. Redis will not throw any exceptions when you try to access a non-existent key.
After every lpush
, call ltrim
to trim the list to 10 elements
See http://redis.io/commands/ltrim
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With