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