How can I know the size (in KB) of a particular key in redis?
I'm aware of info memory
command, but it gives combined size of Redis instance, not for a single key.
相关问题
- What uses more memory in c++? An 2 ints or 2 funct
- Memory for python.exe on Windows 7 python 32 - Num
- Getting Redis Master address from Sentinel C#
- Storing values with duplicate keys in TreeMap, Has
- Configuring Redis to play nice with AppHarbor
You currently (v2.8.23 & v3.0.5) can't.
The
serializedlength
fromDEBUG OBJECT
(as suggested by @Kumar) is not indicative of the value's true size in RAM - Redis employs multiple "tricks" to save on RAM on the one hand and on the other hand you also need to account for the data structure's overhead (and perhaps some of Redis' global dictionary as well).The good news is that there has been talk on the topic in the OSS project and it is likely that in the future memory introspection will be greatly improved.
Note: I started (and stopped for the time being) a series on the topic - here's the 1st part: https://redislabs.com/blog/redis-ram-ramifications-i
I know this is an old question, but, just for the record, Redis implemented a
memory usage <key>
command since version 4.0.0.The output is the amount of bytes required to store the key in RAM.
Reference: https://redis.io/commands/memory-usage
If you just want to get the length of a key (string): STRLEN
Why not try
This will append nothing to the existing value but return the current length.
DEBUG OBJECT <key>
reveals something like theserializedlength
of key, which was in fact something I was looking for... For a whole database you need to aggregate all values for KEYS * which shouldn't be too dfficult with a scripting language of your choice... The bad thing is that redis.io doesn't really have a lot of information about DEBUG OBJECT.