Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a simple redis installation and it seems to slowly eat more and more ram at a steady incline until I restart the redis server.

I'm using redis as a caching layer, currently I don't set an expire on my keys as I didn't think that was necessary. I thought redis would drop off old keys or something - though clearly this isn't happening.

Whats the best way of handling this kind of situation, should I set a short expire time on my keys or is there some functionality built into redis to expire old keys to make room for new ones?

Thanks in advanced!

share|improve this question
1  
Redis isn't memcached, you know. –  womble Aug 10 '11 at 23:10
add comment

2 Answers

Redis's old tag line is: "A persistent key-value database with built-in net interface written in ANSI-C for Posix systems".

I believe keys are persistent by default. You'll have to set EXPIRE on keys that you actually want to go away after a while. As womble noted, it ain't memcached.

For the command reference: http://redis.io/topics/expire

share|improve this answer
    
Thanks for your comments :) I think i'll move to something like memcached instead as although redis works great... it wasn't really built for this. –  tarnfeld Aug 11 '11 at 6:01
add comment

You can set the maxmemory configuration variable in your redis conf and then set the maxmemory-policy to either allkeys-lru or allkeys->random which will allow keys to be removed from the database and make redis act like a cache. Since you're using it as a cache you can comment out all save lines so redis won't save to disk.

This is probably the easiest way and you won't have to switch to memcached, I suggest the allkeys-lru which will allow any key to be removed with the ones that are least recently used being removed first.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.