Redis Study notes One

Source: Internet
Author: User
Tags crc32 download redis
What's Redis?

Redis is an open-source, Key-value database that is written in C, that supports network interaction, and can be based on memory and persistence.

Redis's official website address, very good remember, is Redis.io. (specially checked, the domain name suffix io belongs to the national domain name, is British Indian Ocean territory, that is, the British Indian Ocean Territory) at present, VMware is financing Redis project development and maintenance.

Redis is completely open source free, compliant with the BSD protocol, and is a high-performance key-value database.

Redis and other Key-value cache products have the following three features:

1.Redis supports the persistence of data, can keep the data in memory on disk, restart can be loaded again to use.

2.Redis not only supports simple key-value types of data, but also provides storage of data structures such as List,set,zset,hash.

3.Redis supports data backup, that is, data backup in Master-slave mode.


Redis Advantage

1. The performance is extremely high –redis can read the speed is 110,000 times/s, writes the speed is 81,000 times/s.

2. Rich data types –redis supports binary case Strings, Lists, hashes, Sets, and Ordered Sets data type operations.

3. All operations of atomic –redis are atomic, while Redis also supports the atomic execution of several operations.

4. Rich features –redis also support publish/subscribe, notification, key expiration and so on.

 

Redis can do a lot of things, here is a Redis author talk about the Redis of the application of the scene, the individual feel very good, redis more profound cognition. Address: http://blog.csdn.net/dizzthxl/article/details/8498875


Redis is different from other Key-value storage

Redis has more complex data structures and provides atomic operations to them, which is a different evolutionary path from other databases. Redis data types are based on basic data structures and are transparent to programmers without the need for additional abstraction.

Redis is run in memory but can be persisted to disk, so it is necessary to weigh memory when reading and writing to different datasets, the amount of data should not be greater than hardware memory. Another advantage of the memory database is that it is very simple to operate in memory compared to the same complex data structure on disk, so that Redis can do a lot of internal complexity. At the same time, they are compact in terms of disk format, because they do not require random access.


Download Redis

Http://www.cnblogs.com/edisonfeng/p/3571870.html



The mechanism of Redis persistence

1. Timing snapshot Mode (snapshot):

The persistence method is actually a timer event inside the Redis, every fixed time to check whether the current data changes the number of times and time to meet the configuration of the persistent trigger conditions, if satisfied with the operating system fork to create a subprocess, This subprocess, by default, shares the same address space as the parent process, where it can traverse the entire memory for the storage operation, while the main process can still provide the service, when there is writing by the operating system according to the Memory page (page) Copy-on-write to ensure that the parent-child process does not interact with each other.

The main disadvantage of this persistence is that a timed snapshot represents only a memory image over a period of time, so system restart loses all data between the last snapshot and the reboot.

2. Based on the statement append Method (AOF):

AoF Way is actually similar to MySQL based on the Binlog way, that is, each will make the Redis memory data changes in the command will be appended to a log file, that is, the log file is Redis persistent data.

The main drawback of AOF's approach is that appending log files can result in too much volume, and when the system restarts the recovery data it is aof to load the data very slowly, dozens of g of data may take several hours to load, of course, this time is not due to slow disk file read, Instead, all commands read are executed in memory. In addition, because each command has to write log, the way to use AOF, Redis read and write performance will also be reduced.

3. Virtual Memory Mode:

Virtual memory mode is a redis to the user space for the exchange of data into a strategy, this way in the implementation of the effect is relatively poor, the main problem is the code complex, restart slow, replication slow and so on.

4.diskstore mode:

Diskstore Way is the author abandoned the virtual memory mode after the choice of a new implementation, that is, the traditional way of B-tree, is still in the experimental phase, the follow-up is available we can wait and see.

5. Selection of the persistence mechanism

When the business does not need data persistence, it is of course possible to turn off all persistence methods for optimal performance and maximum memory usage, and if you need to use persistence, choose between the snapshot mode and the statement append mode depending on whether you can tolerate the restart. Do not use virtual memory and Diskstore methods. For now, individuals feel that choosing the AOF is the best choice.

The persistence mechanism that is difficult to choose is mainly snapshot and aof way. Compared to aof snapshots, the feature is faster and faster to recover. But there is a little more data missing when downtime.

When the aof and snapshots are open at the same time, the data recovery will first use the AoF file to restore, when the recovery failed to consider the snapshot.

Redis Partition

Partitioning is the process of splitting data into multiple Redis instances, so each instance holds only a subset of the key.

1). Advantages of Zoning

By leveraging the memory and values of multiple computers, we are allowed to construct larger databases.

Through multi-core and multiple computers, allows us to expand computing power, through multiple computers and network adapters, allowing us to extend network bandwidth.

2). Shortage of partitions

Some of the features of Redis do not perform well in partitioning:

Operations involving multiple keys are usually not supported. For example, when two sets are mapped to a different Redis instance, you cannot perform intersection operations on these two set.

Redis transactions involving multiple keys are not available.

When using partitions, data processing is more complex, such as if you need to process multiple rdb/aof files and back up persistent files from multiple instances and hosts.

Adding or removing capacity is also more complex. Most of the Redis clusters support the ability to increase and remove transparent data balances at runtime, but similar to other systems such as client partitions and proxies do not support this feature. However, a technology called presharding is helpful.

3). Partition type

Redis has two types of partitions. Assuming that there are 4 Redis instance R0,R1,R2,R3, and a number of key representations such as User:1,user:2, there are several different ways to set the key to select which instance the key is stored in. In other words, there are different systems to map a key to a Redis service.

1. Range Zoning

The simplest way to partition is by scope, which is to map a range of objects to a specific Redis instance. For example, users with IDs from 0 to 10000 will be saved to the instance R0,id from 10001 to 20000 users will be saved to R1, and so on. This approach is feasible, and in practice, the disadvantage is to have an interval range to the instance of the mapping table. This table is managed and requires mapping tables for various objects, and is often not a good way to Redis.

2. Hash partition

Another partitioning method is a hash partition. This applies to any key, and does not need to be object_name: This form, like this: using a hash function to convert the key to a number, such as using the CRC32 hash function. Performing CRC32 (foobar) on key foobar outputs an integer similar to 93024922. With this integer modulo, converting it to a number between 0-3, you can map this integer to one of the 4 Redis instances. 93024922% 4 = 2, which means that key foobar should be stored in the R2 instance. Note: The modulo operation is the remainder that is removed and is typically implemented in a variety of programming languages using the% operator.

Java and Redis ———— personal use of Jedis, preferred.



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.