Simple implementation of the sorting function in the Redis cache

Source: Internet
Author: User
Tags mysql update server memory

1. Before implementing the cache ordering function, you must understand the rationality of this function. Think about it, since it can be sorted in the database, why put the sorting function in the cache? Here's a brief summary of two reasons: first, sorting increases the load on the database, it is difficult to support high concurrency, and second, sorting in the cache does not encounter table locking issues. Redis happens to provide sorting capabilities, allowing us to easily implement cache ordering.

2.

Application of Redis to read and write data, while using the queue processor timing to write data to MySQL.
3.
When Redis starts, go to MySQL to read all the table key values into Redis, when you write data to Redis, the Redis primary key is increased and read, and if the MySQL update fails, you need to clear the cache and synchronize the Redis primary key in a timely manner.

This process, mainly in real-time to read and write Redis, and MySQL data through the queue asynchronous processing, to alleviate the MySQL pressure, but this method is mainly based on high concurrency, and Redis's highly available cluster architecture is relatively more complex, generally not recommended.

4.
Redis Configuration

As a cache server, if you do not limit memory, it is very likely that the entire server memory consumption, can be set in the Redis configuration file:

# Limit up to 1.5GB memory MaxMemory 1536MB

If the memory reaches the specified upper limit and adds more cache content to the Redis, the policy for cleaning up the content needs to be set:

# Set the policy to clean up the data corresponding to the least used key Maxmemory-policy ALLKEYS-LRU

Simple implementation of the sorting function in the Redis cache

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.