Redis source code parsing (1): Introduction, redis source code parsing Introduction

Source: Internet
Author: User

Redis source code parsing (1): Introduction, redis source code parsing Introduction
Zookeeper

The author of Redis, Salvatore Sanfilippo, is from Sicily, Italy and now lives in Catania. He currently works at Pivotal. The network name used is antirez.

Redis is an open-source log-type, nosql, and Key-Value database written in ansi c language that supports the network and can be persistent based on memory. It also provides APIs in multiple languages. It can also be viewed as a cache system. It differs from Memcache in that it is persistent and the latter is completely memory-based. It also supports more value types. In addition to strings, it also supports lists (linked list), sets (SET), and zsets (sorted set) data types.

Redis command reference (Chinese) Address: http://redis.readthedocs.org/en/latest /.

Redis learning tutorial (English) Address: http://labs.alcacoop.it/doku.php? Id = articles: redis_land

Redis performance test: http://www.cnblogs.com/lovecindywang/archive/2011/03/03/1969633.html

Redis persistence Mechanism

Redis supports a wide range of data structures in the memory. It is difficult to persistently organize these complex memory types to disks, therefore, there are many differences between Redis persistence methods and traditional databases. Redis supports four persistence methods:

  • Timed snapshot method (snapshot)
  • Statement-based file appending method (aof)
  • Virtual Memory (vm)
  • Diskstore Method

In terms of design ideas, the first two methods are based on the fact that all data is in the memory, that is, the disk landing function is provided for small data volumes, the next two methods are the authors trying to store data that exceeds the physical memory, that is, big data storage. As of this article, the last two persistence methods are still in the experimental phase, in addition, the vm method has basically been abandoned by the author, so only the first two methods can be used in the production environment, in other words, Redis can only be used as storage of small data volumes (all data can be loaded into the memory). Massive Data Storage is not what Redis is good. The persistence methods are described as follows:

Scheduled snapshot method (snapshot ):

This persistence method is actually a timer event in Redis. It checks whether the number and time of changes to the current data meet the configured persistent triggering conditions at a fixed time, if yes, a sub-process is created through the fork call of the operating system. By default, the sub-process shares the same address space with the parent process, in this case, the sub-process can be used to traverse the entire memory for storage operations, while the main process can still provide services. When there is a write, the operating system will follow the Memory page) to ensure that the parent and child processes do not affect each other.

The main disadvantage of this persistence is that the scheduled snapshot only represents the memory image for a period of time, so the system will lose all the data between the last snapshot And the restart.

Statement-based append (aof ):

The aof method is similar to the statement-based binlog method of mysql. That is, each command that changes the Redis memory data is appended to a log file, that is to say, this log file is the persistent data of Redis.

The main disadvantage of aof is that the append log file may lead to a large volume. When the system restarts to restore data, if aof is used, the data loading will be very slow, it may take several hours to load dozens of GB of data. Of course, this time is not because the disk file reading speed is slow, but because all the read commands must be executed in the memory. In addition, because every command has to write logs, the Read and Write Performance of apsaradb for Redis will also decrease with the aof method.

Virtual Memory mode:

The virtual memory mode is a Redis policy for switching data in and out of user space. This mode has poor implementation performance. The main problem is that the Code is complex, the restart is slow, and the replication is slow, it has been abandoned by the author.

Diskstore mode:

The diskstore method is a new implementation method that the author chooses after giving up the virtual memory method, that is, the traditional B-tree method. It is still in the experimental stage, we can wait and see if it will be available in the future.

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.