Two modes of Redis and database processing data

Source: Internet
Author: User

reprinted from :http://www.cnblogs.com/lansexin/archive/2012/11/30/2796404.html 1.1 line

Redis is a high-performance Key-value database. The emergence of Redis, to a large extent, compensates for the lack of memcached such key-value storage, in some cases can be a good complement to the relational database. It provides the python,ruby,erlang,php client, which is very convenient to use.

1. According to our general use of Redis scenario should be this:

That is to say: We will first go to Redis to determine whether the data exists, if it exists, then directly return the cached data. And if it doesn't exist, it goes to the database, reads the data, and caches the data in Redis.

Applicable occasions: If the amount of data is large, but not frequently updated (such as user ranking)

2. The use of the second Redis differs from the first, depending on the situation:

Here we will first go to Redis to determine whether the data exists, if it exists, then directly update the corresponding data (this step will be updated to record the key, such as also saved to redis such as: Key: Save_update_keys "with Lpush list record"), and return the updated data to the page. If it does not exist, it will update the contents of the database and then save the data to Redis. Behind the work: the background will have a mechanism to the Redis Save_update_keys stored key, respectively, to find the corresponding data, updated to the DB.

Advantage: The main purpose of this process is to use Redis as a database, updating the fetch data faster than DB. Ideal for frequent changes in large data volumes (such as Weibo).

Cons: The reliance on Redis is great, and it's important to keep the data in the downtime. (However, if you can use Redis's snapshot aof, you should not have much impact if you recover quickly, because even if Redis does not work, it will not affect the processing of subsequent data.) )

Difficulty: In the pre-planning key format, the storage type is important because it affects the ability to synchronize data to DB.

Two modes of Redis and database processing data

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.