Redis-rdb-tools is a tool written by Python for analyzing Redis's rdb snapshot files, which can generate a JSON file from an RDB snapshot file or generate a report to analyze the usage details of Redis and compare two dump files using the standard diff tool. In short, it is a more practical tool, as the installation can be installed by Python pip
[[email protected] ~]# yum-y install PYTHON-PIP python-redis[[email protected] ~]# pip install Rdbtools
Of course, you can also download the source code to install, but you must install the Python-redis plug-in, as follows:
git clone https://github.com/sripathikrishnan/redis-rdb-toolscd redis-rdb-toolspython setup.py Install
Similar to glances, after installation, a Python script named Rdb is called, and several parameters are commonly used by the RDB:
-h,--help Display this help message and exit -c FILE, --command=FILE the type of the command to be executed, which goes out. Valid commands are JSON (turn to JSON), diff (Difference pair), Justkeys (only key), Justkeyvals (only value), Memory (RAM report), protocol (lead to add command) -f FILE, --file=FILE file Output File -n DBS, --db=DBS dbs database number. You can provide multiple databases. If not specified, all databases will be included. -k KEYS, --key=KEYS shows the key of Redis. This can be a regular expression -o NOT_KEYS, --not-key=NOT_KEYS display ignored key. This can be a regular expression -t TYPES, --type=TYPES display the data type, key data type string (string), List (linked list), set (set), Zset (sorted set --ordered collection) and hash (hash type), if not specified, all data types will be returned -b bytes, --bytes=BYTES limit the memory output to a key greater than or equal to the unit byte -l largest, --largest= largest limit the memory output to only the first n keys (by size) -e ESCAPE, --escape=ESCAPE escapes the string as encoded: Raw (default), Print,utf8, or base64.
If you need to match the key to the key and value is printed in JSON format:
[[email protected] ~]# RDB--command json-k "test"/usr/local/redis/dump.rdb
In addition, the most common use of Redis's RDB Memory Analysis report generates a CSV file, which can be analyzed using tools such as awk, or the database can be imported for analysis:
[Email protected] redis]# rdb-c memory Dump.rdb > Memory.csv
In the generated report there is database (key in Redis db), type (key type), key (key value), Size_in_bytes (memory size of key), encoding (storage encoding of value), num_ Elements (the number of value in key), len_largest_element (the length of value in key), it is important to note that if you import a database, you must be aware of the field data type used when importing, such as importing the table DDL in MySQL:
CREATE TABLE ' memory ' (' database ' int (+) default NULL, ' type ' varchar) default NULL, ' KEY ' varchar (+) Default NULL, ' Size_in_bytes ' bigint () default null, ' encoding ' varchar (+) default NULL, ' Num_elements ' bigint (default) NULL, ' len_largest_element ' varchar (+) DEFAULT NULL, PRIMARY key (' key '));
Redis Memory Analysis Tool-redis-rdb-tools