5 common usage Scenarios for Redis Submitmy comments
Load in
have commented
5 common usage Scenarios for Redis
2015-07-23Database developmentDatabase Development
Database Development
number Dbdevs
Function Introduction Share database-related technical articles, tutorials, and tools, plus database-related work. Occasionally talk about the programmer's life:)
(Click the blue Word above to quickly follow us)
English: Joe Engel
Translator: Bole Online-RSS
Website: http://blog.jobbole.com/88383/
Click "Read original" To view this page
In this article, we will describe the most common usage scenarios for Redis, and the different features that affect our choices.
1. Session Cache
One of the most common scenarios for using Redis is the session cache. The advantage of using a Redis cache session over other storage (such as memcached) is that Redis provides persistence. When maintaining a cache that is not strictly consistent, if the user's shopping cart information is lost, most people will be unhappy, now, they will do this?
Fortunately, with Redis's improvements over the years, it's easy to find out how to properly use Redis to cache your session's documentation. Even the well-known business platform Magento offers Redis plugins.
2, full-page cache (FPC)
In addition to basic session tokens, Redis offers a simple FPC platform. Back to the consistency issue, even though the Redis instance was restarted, because of the persistence of the disk, the user will not see a drop in page loading speed, which is a great improvement, similar to PHP native FPC.
Again, for example Magento, Magento provides a plug-in to use Redis as the full-page cache backend.
In addition, for WordPress users, Pantheon has a very good plug-in Wp-redis, this plugin can help you to load the fastest speed you have visited the page.
3. Queue
One of the great advantages of Reids in the memory storage engine area is the provision of list and set operations, which enables Redis to be used as a good Message Queuing platform. The operation that Redis uses as a queue is similar to the push/pop operation of a local program language (such as Python) on a list.
If you quickly search for "Redis queues" in Google, you'll soon be able to find lots of open source projects that are designed to use Redis to create very good back-end tools to meet a variety of queue requirements. For example, celery has a background where redis is used as a broker, which you can view from here.
4. Leaderboard/Counter
Redis's operation of incrementing or decreasing numbers in memory is very well implemented. The set (set) and the ordered set (Sorted set) also make it very simple to perform these operations, and Redis just provides the two data structures exactly. So, we're going to get the top 10 users from the sorted collection – What we call "User_scores", we just need to do it like this:
Of course, it is assumed that you are doing an incremental sort based on your user's score. If you want to return users and users ' scores, you need to do this:
Zrange User_scores 0 Withscores
Agora Games is a good example of what you can see in Ruby, which uses Redis to store data.
5. Publish/Subscribe
Last (but certainly not least) is the Publish/Subscribe feature of Redis. There are really a lot of usage scenarios for publish/subscribe. I've seen people use it in social networking connections, as a publish/subscribe-based scripting trigger, and even use Redis's publish/Subscribe feature to build chat systems! (No, it's true, you can check it out).
All of the features that Redis offers, I feel this is the least of the people who like it, although it provides users with this versatility.
Wait a minute?
Dear reader, What do you think of it? What are you going to do with Redis?
database development
Number:dbdevs
Build the best database number in the old hemisphere
--------------------------------------
Business cooperation qq:2302462408
Recruitment and headhunting Service qq:2302462408
Submission URL: top.jobbole.com
Read the original reading
Report
Sweep
Follow the public number
From for notes (Wiz)
5 common usage Scenarios for Redis