hh54188
hh54188

Reputation: 15626

Redis: How can I check how much memory used in real time?

I want check how much memory used in real time, for instance, each time I set or insert some data, I want to know how much memory increased and how much used totally.

I try to use INFO command, and check the used_memory or used_memory_* property would work or not, but sorry I found it only show the memory allotted by the system, cuz each time I check it after I insert new data, they still stay the same

Is there any way I can check the real time memory used in Redis?

Upvotes: 5

Views: 5327

Answers (1)

Didier Spezia
Didier Spezia

Reputation: 73226

The used_memory field is what you are looking for. It is not the memory allocated by the system as you said, this is the memory given by the process memory allocator to Redis.

Example:

> info memory
...
used_memory:541368
...
> set y "titi"
OK
> info memory
...
used_memory:541448       # i.e. +80 bytes
...
> del y
(integer) 1
> info memory
...
used_memory:541368
...

Please note that Redis does a number of memory related optimizations. For instance, it is able to factorize values containing small integers. Or, if you append data to an existing string, the corresponding buffer will not grow at each append operation. So depending on these optimizations, the memory usage increase/decrease for a given set of operation is not always consistent.

Upvotes: 6

Related Questions