Get Redis key's memory usage

2,740 views
Skip to first unread message

Dinesh Joshi

unread,
Nov 23, 2014, 3:46:18 PM11/23/14
to redi...@googlegroups.com
Given a key, I'm looking to get back the memory utilization of the key. Is there a redis command that'll allow me to get this statistic? This is important to analyze the memory consumption on the key level. I see there are rdb analysis tools that allow me to do something similar however, I'd like to do it in an online manner where I could query the redis server for this info.

Marc Gravell

unread,
Nov 23, 2014, 4:41:13 PM11/23/14
to redi...@googlegroups.com

I'm not at a PC, but IIRC "debug object {key}" returns the "serializedlength". This is, however, entirely undocumented and unsupported - and I don't even know if what it returns can be translated into regular memory usage etc. Another option could be "dump {key}" and measure it - ideally via lua so you don't pay for the bandwidth.

Marc

On 23 Nov 2014 21:07, "Dinesh Joshi" <dinesh....@gmail.com> wrote:
Given a key, I'm looking to get back the memory utilization of the key. Is there a redis command that'll allow me to get this statistic? This is important to analyze the memory consumption on the key level. I see there are rdb analysis tools that allow me to do something similar however, I'd like to do it in an online manner where I could query the redis server for this info.

--
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 http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Josiah Carlson

unread,
Nov 23, 2014, 7:43:31 PM11/23/14
to redi...@googlegroups.com
The serializedlength field is how large the data would be if it was part of a snapshot or was DUMPed. You can save yourself some memory allocation by sticking with DEBUG OBJECT.

In terms of actual memory used, no, there currently isn't a function to do so.

 - Josiah

Sripathi Krishnan

unread,
Nov 24, 2014, 12:46:20 AM11/24/14
to redi...@googlegroups.com
I see there are rdb analysis tools that allow me to do something similar however, I'd like to do it in an online manner where I could query the redis server for this info.

rdb does allow you to do it in an online manner. Run this command - 

redis-memory-for-key -s localhost -p 6379 -a mypassword person:1 

It connects to the redis server using the provided credentials, does a dump on the specified key, and then estimates the memory. See https://github.com/sripathikrishnan/redis-rdb-tools/blob/master/rdbtools/cli/redis_memory_for_key.py#L43



--Sri

Dinesh Joshi

unread,
Nov 25, 2014, 1:04:45 AM11/25/14
to redi...@googlegroups.com
Thank you all for the input. 
Reply all
Reply to author
Forward
0 new messages