Go 5 common usage Scenarios for Redis

Source: Internet
Author: User

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.

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?

Go 5 common usage Scenarios for Redis

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.