tags:

views:

59

answers:

3

I am using redis for caching but recently I ran into a problem with the amount of memory used - had to restart my server since all ram had been consumed.

It's not the biggest machine but how should I configure redis to avoid the same problem again?

free -m
             total       used       free     shared    buffers     cached
Mem:           240        222         17          0          6         38
-/+ buffers/cache:        177         62
Swap:          255         46        209

I have changed the following settings:

timeout 60
databases 1
save 300 1
save 60 100
maxmemory 104857600

top
top - 14:15:28 up  1:19,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:  49 total,   1 running,  48 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    245956k total,   228420k used,    17536k free,     6916k buffers
Swap:   262136k total,    47628k used,   214508k free,    39540k cached
A: 

Unlike memcached, redis is supposed to be a databse; so it won't automatically remove old values to make room for new ones.

You have to explicitly set the expire time for each key/value, and even then you could overflow if you create key/values faster than that.

Javier
thank you, I will do so, but what about configuration based on available memory? I just checked my code and I am using setTimeout() everywhere a new key is added
kristian nissen
+1  A: 

Use Redis virtual memory in Redis 2.0: http://antirez.com/post/redis-virtual-memory-story.html

+1  A: 

Hello, you can use the "maxmemory" directive in the config file: when this amount of memory is exceeded then Redis will expire earlier keys having already an expire set (the keys that would expire sooner are the first that will be removed).

antirez