Tips for using Redis caching for query results

Source: Internet
Author: User
Tags redis

First of all, because of the recent project used cache Redis and there are more query paging, so use a pageentity class, so that entity classes need to use the time to inherit the page.

Use this class.


Your sort is more sour.


And then, how.


1, the design of the table, you must have this three fields Create_time, status, Status_time


2, according to these three fields to filter the data scene is too much


3, if these three fields can not meet your query data needs, so good to do, extends this pageentity


4, so, you do not need to write so many strange query of the paging SQL.



For too many queries we can fix this: cache the results of the query.

Cached key, with Getattrval4forrediskey.getattrval4forrediskey,


This is hset, and the structure inside is


Total:xxx page1 List1 page2 List2 .....


The cache has a valid time of 30 seconds.


The advantages of doing so is self-evident that many pages, users silly not to pull a few, will not enter so many conditions, is the condition, we do not need to query many times, is not ....


Here's how the Redis is drafted:



Combined with the first two, one way we design the table can be easy to page and conditionally query, and very good query results are also cached, very good to reduce the number of repeated queries

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.