How to spot unused keys in a redis instance taking up 85% memory ?

94 views
Skip to first unread message

黄雅冠

unread,
Jul 5, 2016, 2:14:56 AM7/5/16
to Redis DB
I have a redis instance running as cache in the production environment. But I also put some data without ttl in it for convenience. 

The memory get larger and larger, increasing from 60% to 85% in two month. I suspected I have some keys like "prefix:${uid}" where ${uid} is variable and I forgot to set ttl on them.I want to find them out.

I have find redis-rdb-tools. The problem is I can't get the rdb file. Since the redis takes up more than 50% memory. Once I enable rdb file, it will crash for "out of memory".

Is there any good suggestion for the task ?

I am using redis 3.0 in standalone mode.

Thanks

---
hyg

Marc Gravell

unread,
Jul 5, 2016, 2:39:00 AM7/5/16
to redi...@googlegroups.com

You can use SCAN or KEYS to query the keys on the server, to test your idea. Getting the size per key is trickier, but I am to recall that DEBUG OBJECT (which is not really documented and not really intended for use by clients) gives an indicative size. These can be used without requiring the rdb.

However, it wouldn't surprise me if saving it worked fine. This uses fork, which uses (normally) copy-on-write; you don't usually need twice the memory to fork. But i understand your reluctance to risk it with production data.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

黄雅冠

unread,
Jul 5, 2016, 2:54:54 AM7/5/16
to Redis DB
I have tested bgsave once, and monitored the memory. It decreased sharply, and I kill the forked process immediately before it crash :) .

在 2016年7月5日星期二 UTC+8下午2:39:00,Marc Gravell写道:

CharSyam

unread,
Jul 5, 2016, 3:08:15 AM7/5/16
to redi...@googlegroups.com
Could you accept not to use redis a while?
you can use save command. but at that time redis never return for requests.
and also you can use scan command.

and if you want to make rdb. with bgsave
try to "sysctl vm.overcommit_memory=1"

hyg

unread,
Jul 5, 2016, 5:25:36 AM7/5/16
to Redis DB
Thanks, I forgot save command.  But for production env, I will take the scan command solution.

在 2016年7月5日星期二 UTC+8下午3:08:15,CharSyam写道:
Reply all
Reply to author
Forward
0 new messages