Common specifications for Redis development

Source: Internet
Author: User
Tags redis server memory
1. Separation of hot and cold data, do not put all the data in the Redis

Although Redis supports persistence, the data storage for Redis is all in memory and costly. It is recommended to store only high-frequency thermal data in Redis "QPS greater than 5000", for low-frequency cold data can use disk-based storage such as MYSQL/ELASTICSEARCH/MONGODB, not only to save the memory cost, and the small amount of data in the operation faster, Higher efficiency. 2. Different business data to be stored separately

Do not place irrelevant business data in a Redis instance, and suggest new business requests for a new, separate instance. Because Redis is single-threaded, isolated storage reduces the impact of different business interactions, increases request responsiveness, and avoids the excessive expansion of individual instance memory data, which can be restored faster in the event of an exception. 3. Specification of key format

The right key for easy viewing, statistics, and troubleshooting.
Like what:

Gateway Gw
Platform Name platform abbreviation

"Platform abbreviation" + ":" + "project name" + ":" + "business meaning"
Example: GW:TRADE:USERID
GW is a new gateway, trade is a trading item and UserID is the business ID.

":"-as a key delimiter, convenient for client tools as a catalog rating 4. Stored key Be sure to set the timeout time

If the app locates Redis for cache caching, you must set the timeout for the stored key. Because if not set, these keys will always take up memory not released, resulting in a great waste, and over time will lead to more memory consumption until the server memory limit is reached. In addition, the timeout length of key must be based on the business evaluation, not the longer the better. (Some business requires key to be valid for long term.) You can set the time-out period for each write, allowing the timeout to be postponed. )

public  Boolean Set (final  byte [] key,  final  byte [] value,  final  long  liveTime ) {        return  redistemplate.execute (new  rediscallback< Boolean> () {            public  Boolean Doinredis ( Redisconnection connection)   throws  DataAccessException {                 Connection.set (key, value);                 if  (livetime >  0) {                     Connection.expire (key, Livetime);                }                 
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.