How to measure the size of various data in Redis

Source: Internet
Author: User
Tags redis cluster install redis
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.