0

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!

1
  • 1
    Redis isn't memcached, you know.
    – womble
    Aug 10, 2011 at 23:10

2 Answers 2

1

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

1
  • 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, 2011 at 6:01
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .