lua - Redis Capped Sorted Set, List, or Queue? -


has implemented capped data-structure of kind in redis? i'm working on building news feed. feed wind being manipulated , read frequently, , holding in sorted set in redis cheap , perfect use case. issue ever need n items per feed, , i'm worried memory overflow, i'd ensure each feed never gets above n items. seems pretty trivial make capped sorted collection in redis lua:

redis-cli eval "$(cat update_feed.lua)" 1 feeds:some_feed "thing_to_add", n 

where update_feed.lua looks (without testing it):

redis.call('zadd', keys[1], os.time(), argv[1]) local num = redis.call('zcard', keys[1]) if num > argv[2]:     redis.call('zremrangebyrank', keys[1], -n, -inf) 

that's not bad @ all, , pretty cheap, seems such basic thing doable more cheaply instantiating sorted set n buckets begin with. can't find way in redis, guess question is: did miss something, , if didn't, why there no structure in redis, if ran basic lua script described, seems typical enough use-case ought implemented option redis data structures?

you can use ltrim if list.

excerpt documentation.

lpush mylist someelement ltrim mylist 0 99 

this pair of commands push new element on list, while making sure list not grow larger 100 elements. useful when using redis store logs example. important note when used in way ltrim o(1) operation because in average case 1 element removed tail of list.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -