I have a redis instance which keeps growing in memory to the point where something is clearly going wrong with my application logic, I have tens of thousands of keys and want to find out which are the bigest users of memory. Is there a know technique to solve this?
I'd think that the way to go is not finding which of your keys are the biggest, but what characteristics do your keys have - i.e. what sort of data they hold.
Redis is not a replacement for a relational database, it is a complementary tier (very important and usefuly but still complementary). You use it to accelerate access to data in your application in various ways. That means that at the end of the day, Redis should probably not include everything but only the most frequently used data, and/or general statistics and aggregations.
I don't know your application's domain, but try looking for expiration for keys, for the beginning. Keys that are infrequently accessed should eventually be deleted.
As a further step I would check for redundant keys, that is - the same data being saved in multiple forms.
Note: There is absolutely nothing wrong with redundancy in Redis, in fact that's a recommended pattern to go with (use Redis without normalization, in favor of speed of access for every given query). All I'm suggesting is that you might find some classes of keys that are completely useless given other ones, i.e. they don't add any speed advantage and just inflate your Redis database.
Try have a look at some Redis GUI applications that might assist you exploring your runtime Redis instance:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With