If the MySQL database is large, we can easily find out which tables occupy the space. However, if the Redis memory is large, it is not easy to find out which tables occupy the space.
If the MySQL database is large, we can easily find out which tables occupy the space. However, if the Redis memory is large, it is not easy to find out which tables occupy the space.
If the MySQL database is large, we can easily find out which tables occupy the space. However, if the Redis memory is large, it is not easy to find out which tables occupy the space) the space occupied by the key.
Some tools can provide necessary help. For example, redis-rdb-tools can directly analyze RDB files to generate reports. Unfortunately, it cannot fully meet my needs, I don't want to perform secondary development on the basis of it. In fact, developing a dedicated tool is very simple. Using commands such as SCAN and DEBUG, there is not much code to achieve:
SetOption (Redis: OPT_SCAN, Redis: SCAN_RETRY); $ result = array_fill_keys ($ patterns, 0); while ($ keys = $ redis-> scan ($ it, $ match = '*', $ count = 1000) {foreach ($ keys as $ key) {foreach ($ patterns as $ pattern) {if (preg_match ("/^ {$ pattern} $/", $ key) {if ($ v = $ redis-> debug ($ key )) {$ result [$ pattern] + = $ v ['serializedlength'];} break ;}}} var_dump ($ result);?>
Of course, the premise is that you need to summarize the possible key modes in advance, the simple but not rigorous method is MONITOR:
Shell>/path/to/redis-cli monitor | awk-F '"'' $2 ~ "ADD | SET | STORE | PUSH" {print $4 }'
In addition, it should be noted that, because the serializedlength returned by DEBUG is the length after serialization, the final calculated value is smaller than the actual memory usage, but considering the relative size, it is still of reference significance.
Install and test Redis in Ubuntu 14.04
Redis cluster details
Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis
Redis series-installation, deployment, and maintenance
Install Redis in CentOS 6.3
Learning notes on Redis installation and deployment
Redis. conf
Redis details: click here
Redis: click here
This article permanently updates the link address: