Re: can add a command "size" to see a key how it memory used?

3,078 views
Skip to first unread message

Didier Spezia

unread,
Sep 13, 2012, 4:42:34 AM9/13/12
to redi...@googlegroups.com

Try the DEBUG OBJECT command: it returns the serialized length of a given key.

Regards,
Didier.

On Thursday, September 13, 2012 3:56:15 AM UTC+2, mike wrote:
can add a command "size" to see a key how it memory used?

Ori Livneh

unread,
Sep 13, 2012, 4:42:22 AM9/13/12
to redi...@googlegroups.com
Hi,

You can use the (undocumented, AFAIK) command DEBUG OBJECT key, and note the value of "serializedlength".

--
Ori Livneh
o...@wikimedia.org


On Wednesday, September 12, 2012 at 6:56 PM, mike wrote:

> can add a command "size" to see a key how it memory used?
> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/redis-db/-/9FeKg9C3rsEJ.
> To post to this group, send email to redi...@googlegroups.com (mailto:redi...@googlegroups.com).
> To unsubscribe from this group, send email to redis-db+u...@googlegroups.com (mailto:redis-db+u...@googlegroups.com).
> For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.



Sripathi Krishnan

unread,
Sep 13, 2012, 6:11:47 AM9/13/12
to redi...@googlegroups.com
I am afraid the serializedLength is a poor indicator of the actual memory used by the key. When an object is serialized, strings are compressed. Overheads due to pointers are no longer present in the serialized data. 

But there is a way to get a reasonable estimate of memory usage for a key. Use the dump command to generate a binary dump for the key. Then parse this dump using redis-rdb-tools to get a reasonable approximation of memory. 

redis-rdb-tools has 95% of the code to solve this; but it needs some glue code to work off any key on a live redis server. I have created https://github.com/sripathikrishnan/redis-rdb-tools/issues/13 to track this; I'll see if I can implement it this week.

--Sri


To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.

Sripathi Krishnan

unread,
Sep 13, 2012, 5:24:01 PM9/13/12
to redi...@googlegroups.com
I added a new command redis-memory-for-key to rdbtools package. You will have to re-install redis-rdb-tools to run this command.

Notes from readme document : 

redis-memory-for-key person:1

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

Output :


Key             "person:1"
Bytes               111
Type                hash
Encoding            ziplist
Number of Elements      2
Length of Largest Element   8

NOTE :

  1. This was added to redis-rdb-tools version 0.1.3
  2. This command depends redis-py package
--Sri
Reply all
Reply to author
Forward
0 new messages