Redis Research (14)-management tools

Source: Internet
Author: User

工欲善其事, its prerequisite. When using Redis, if you can effectively utilize the various management tools of Redis, it will be much easier to develop and manage.


First, REDIS-CLI

I believe you are already familiar with REDIS-CLI, as the command line client with Redis, you can find it from any server that has Redis installed, so REDIS-CLI is the simplest and most useful tool for managing Redis. REDIS-CLI can perform most of the Redis commands, including the info command to view database information, change the Config command for the database settings, and the Save command to force an RDB snapshot, and the following are some of the most useful commands for managing Redis .


1. Time-consuming command log

When a command execution time exceeds the limit, Redis adds information such as the execution time of the command to a time-consuming command log (slow log) for developers to view. This limit can be set through the Slowlog-log-slower-than parameter of the configuration file, noting that the unit is microseconds (1000000 microseconds is equivalent to 1 seconds) and the default value is 10000. The time-consuming command log is stored in memory, and the number of records can be limited by the Slowlog-max-len parameter of the configuration file.

Use the Slowlog get command to get the current time-consuming command log, such as:

[HTML]View Plaincopyprint?
    1. REDIS>SLOWLOG GET  
    2. 1)  1)   ( Integer)  4  
    3. 2)   (integer)  1356806413  
    4. 3)   (integer)  58  
    5. 4)  1)   "get"   
    6. 2)   "Foo"   
    7. 2)  1)   (integer)  3  
    8. 2)   (integer)   1356806408  
    9. 3)   (integer )  34  
    10. 4)  1)   "Set"   
    11. 2)   "foo"   
    12. 3)   "bar "   


Each log is made up of the following 4 parts:
(1) the log unique ID;
(2) The Unix time of the command execution;
(3) The time-consuming period of the order, in microseconds;
(4) commands and their parameters.
To produce some time-consuming command logs as a demonstration, here the Slowlog-log-slower-than parameter value is set to O, which records all commands. If set to a negative number, the time-consuming command log is closed.


2. Command monitoring

Redis provides the monitor command to monitor all the commands that Redis executes, and REDIS-CLI also supports this command, such as executing Monitor in REDIS-CLI:

[HTML]View Plaincopyprint?
    1. Redis>monitor
    2. Ok


Any commands that Redis executes are printed in redis-cli, as we open another redis-cli to execute the Set Foo Bar command, which in the previous REDIS-CLI outputs the following:

[HTML]View Plaincopyprint?
    1. 1356806981.885237 [0 127.0.0.1:57339] "SET" "foo" "Bar

The Monitor command has a very significant impact on Redis performance, and a client using the Monitor command reduces nearly half of Redis's load capacity. So the monitor command is only suitable for debugging and error correction.


The Instagram team developed a Redis query parser Redis-faina based on the Monitor command. Redis-faina can analyze the most commonly used commands, the most frequently accessed keys, and so on, based on the monitoring results of the Monitor command, which helps to understand how redis is used.

Instagram is Facebook's image-sharing community. Redis-faina Project address is Https://github.com/Instagram/redis-faina, directly download the redis-faina.py file can be used.

The input value of the redis-faina.py is the result of the monitor command execution over time. For example:

[HTML]View Plaincopyprint?
    1. REDIS-CLI MONITOR | Head-n the number of commands to analyze |./redis-faina.py



Second, phpredisadmin


When there are more keys in Redis, it is not very convenient to use REDIS-CLI to manage data, just as someone who manages MySQL likes to use Phpmyadm in, and Redis also has a PHP-developed web-side management tool Phpredisadmin. Phpredisadmin supports the ability to view key lists in a tree structure, edit key values, import/Export database data, view database information, and view key information.


1. Installing Phpredisadmin

Here's how to install Phpredisadmin:

[HTML]View Plaincopyprint?
    1. git clone http S://github.com/erikdubbelboer/phpredisadmin.git
    2. CD Phpredisadmin


Phpredisadmin relies on PHP's Redis client Predis, so you need to perform the following two commands to download Predis:

[HTML]View Plaincopyprint?
    1. Git submodule init
    2. git submodule update


2. Configure Database connections

After downloading the phpredisadmin, you need to configure the Redis connection information. The default phpredisadmin is connected to 127.0.0.1, Port 6379, and you can edit the config.inc.php file in the includes folder if you need to change or add database information.


3. Using phpredisadmin

Install PHP and Web servers (such as Nginx) and store the Phpredisadmin folder in the Site directory for access.

Phpredisadmin automatically separates Redis keys with ":" and displays them in a tree-shaped structure, which is intuitive. Two keys, such as Post:1 and Post:2, are in the post tree.
Click on a key to view the key information, including the type of key, time of life and key values, and can be easily edited.

4. Performance
Phpredisadmin uses the keys command when getting a list of keys, and then uses the type command for all keys to get its data type, so performance is not high when there are very many keys (for a Redis database with 1 million keys, It takes about dozens of milliseconds to use the keys command on an ordinary personal computer. because Redis uses single-threaded processing commands, it is not appropriate to use phpredisadmin management for databases with large volumes of data in production environments.


Third, Rdbtools
Rdbtools is a Redis Snapshot file parser that can export JSON data files based on snapshot files, analyze the footprint of each key in Redis, and more. Rdbtools is developed using Python and the project address is
Https://github.com/sripathikrishnan/redis-rdb-tools.


1. Installing Rdbtools
Install rdbtools using the following command :

[HTML]View Plaincopyprint?
    1. git clone https://github.com/sripathikrishnan/redis-rdb-tools
    2. CD Redis-rdb-tools
    3. sudo python setup.py instal l


2. Generating snapshot files
If you do not enable RDB persistence, you can use the Save command to manually generate a snapshot file for Redis.

3. Export snapshots to JSON format
The snapshot file is in binary format and is not conducive to viewing, and you can use rdbtools to export it to JSON format with the following command:

[HTML]View Plaincopyprint?
    1. Rdb--command Json/path/to/dump.rdb > output_file Name.json

Where/path/to/dump.rdb is the path to the snapshot file, Output_filename.json is the file path to export.

4. Generate a Space usage report
Rdbtools can export the storage of each key recorded in the snapshot file to a CSV file, and you can import the CSV file into data analysis tools such as Excel to analyze the usage of Redis. The command is as follows:

[HTML]View Plaincopyprint?
    1. Rdb-c Memory/path/to/dump.rdb > output_filename.csv
    2. Http://www.youyuanapp.com/thread-11419-1-1.html
      Http://www.youyuanapp.com/thread-11418-1-1.html
      Http://www.youyuanapp.com/thread-11417-1-1.html
      Http://www.youyuanapp.com/thread-11412-1-1.html
      Http://www.youyuanapp.com/thread-11409-1-1.html
      Http://www.youyuanapp.com/thread-11404-1-1.html
      Http://www.youyuanapp.com/thread-11403-1-1.html
      Http://www.youyuanapp.com/thread-11398-1-1.html
      Http://www.youyuanapp.com/thread-11397-1-1.html
      Http://www.youyuanapp.com/thread-11395-1-1.html
      http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101147963/
      http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101251829/
      http://yishujiayuanq.blog.163.com/blog/static/244725061201502510133740/
      http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101653328/
      http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101718995/
      http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101738627/
      http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101822599/
      http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101841318/
      http://yishujiayuanq.blog.163.com/blog/static/2447250612015025101927982/
      http://yishujiayuanq.blog.163.com/blog/static/244725061201502510197287/

Redis Research (14)-management tools

Related Article

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.