Redis Learning Research--basic knowledge

Source: Internet
Author: User

The following content for excerpt reproduced;

1. What is Redis

Redis is an open source, memory-based Key/value storage System written in ANSI C, similar to Memcache, but it supports more value types, including: String, List, collection (set), ordered collection ( Sorted set) and hash tablehttp://blog.nosqlfan.com/html/2235.html, these data types support Push/pop, Add/remove, intersection and set of differences, and other richer operations, And these operations are atomic in nature.

According to the CAP theory of the distributed domain, the three parts of consisency, availability, tolerance to network partitions can only meet two points at the same time when any system architecture is implemented, but not three. Redis is a database that focuses on consisency and availability, so Redis is just a stand-alone key/value system and does not directly support distribution, taking into account the tolerance to network partitions, which supports synchronizing data to multiple slave libraries.

2. What are the advantages of Redis?

Compared to similar products such as Memcache and MySQL, Redis has several advantages:

(1) Very rich data structures, and the common operations of these data structures are atomic;

(2) high-speed reading and writing. Memcached provides a CAS command that guarantees consistency of the same data for multiple concurrent access operations. Redis does not provide CAS commands, but Redis provides the functionality of a transaction that guarantees the atomicity of a sequence of commands and is not interrupted by any action. MySQL uses locks, and memcache does not use locks, which makes it highly efficient. In short, Redis uses its own implementation of the event separator, the code is very short, no CAs, no lock, so the efficiency is very high.

For a comparison of Memcache and Redis, refer to this article: "The comparison of Redis and memcached" http://tech.it168.com/a2011/0818/1234/000001234403_1.shtml

3. What are the drawbacks of Redis

The main drawbacks of Redis are two:

(1) persistence. Redis stores data directly into memory and can be persisted in two ways: Timed snapshots (snapshot) and statement-based append (appendonlyfile,aof). The snapshot method is to write the entire database data to disk at intervals, and it is obvious that all the data is written every time, and the AoF method only tracks the changed data, which is similar to the MySQL Binlog method, but the append log may be too large, At the same time, all operations have to be re-executed again, and the recovery speed is slow.

(2) Memory consumption. Although Redis uses compression algorithm storage for some data structures, it is too expensive to take up the memory.

4. Redis's application Scenario

Antirez, the author of Redis, once laughed at it as a data structure server (data Structures server), and indeed, using Redis's flexible data structures and data operations, we can easily implement a variety of functions, the following are a few typical operations:

(1) Counter

Redis commands are atomic and can easily be used to build counter systems using the INCR, DECR commands

(2) Get the latest N data operations

You can use the list of Lpush and LTrim operations.

(3) Leaderboard application, Top n operation

One of the actions above is to sort by time, and this is a condition for customization, such as the number of clicks, which can be done using the sorted set data structure.

For more application scenarios, refer to a few articles:

"1" "Redis drip": http://www.jeffkit.info/2011/05/994/

7 collection types in "2" Redis scenario: http://blog.prosight.me/index.php/2011/08/802

"3" Redis author on redis application scenario: http://blog.nosqlfan.com/html/2235.html

5. Redis Usage Experience

(1) Select a database Select

For the SQL class database, we can create n databases, and each database corresponds to a name, we usually first select a database, then the database table operations, and Redis is different, in Redis, the database is assigned an integer number (starting from 0), By default, database 0 is manipulated, and the number of databases can be specified in the configuration file redis.conf databases property.

(2) database storage and retrieval

Complete data storage and retrieval directly using the commands on Http://redis.io/commands

(3) Support Services

MULTI, EXEC, DISCARD, and WATCH commands are the cornerstone of Redis transactions. A Redis transaction allows a set of REDIS commands to step into and provides the following two important guarantees: All commands in a transaction are executed serially, or all commands are either not processed by any command. Specifically, you can open this article: http://blog.xiping.me/2010/12/transaction-in-redis.html

(4) Redis Client

Redis supports clients in very various languages, specific to: http://redis.io/clients

original articles, reproduced please specify: reproduced from Dong's blog

This article link address: http://dongxicheng.org/nosql/redis-code-basic-points/

Dong, author Introduction: http://dongxicheng.org/about/

Collection of articles for this blog:http://dongxicheng.org/recommend/

Redis Learning Research--basic knowledge

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.