Latest list of news and articles
The redis key used
public interface RedisKey { String ARTICLE_LIST = "article:list:all"; / / article list String ARTICLE_LIST_SORT_CREATE_TIME = "article: the list: sort: createTime"; / / article creation time String ARTICLE_LIST_SORT_UPDATE_TIME = "article: the list: sort: updateTime"; String ARTICLE_LIST_SORT_VIEWS = "article:list:sort:views"; String ARTICLE_LIST_LOCK = "article:list:lock"; // Lock the article}Copy the code
Steps:
-
To create the article
-
Create it in the database
-
Deposited in the redis
- The key for
Article :list:all: + article ID
, value indicates the value json - The latest list is stored in Redis, sorted set (ZSET) is used, and score is the update time stamp of the article.
- In redis, the sorted set (ZSET) is used to store the list, and score is used to create the timestamp of the article.
- The key for
-
-
Get the list of articles
- through
article:list:sort:createTime
Gets a list of article ids, sorted by creation time. - through
redisTemplate.opsForValue().multiGet
Get the List of articles and return it to the front end as a new List with the key passed in (handwritten for paging).
- through
-
Get the latest list
- through
article:list:sort:updateTime
Gets a list of the most recent article ids (sorted by update time). - through
redisTemplate.opsForValue().multiGet
Get the List of articles and return it to the front end as a new List with the key passed in (handwritten for paging).
- through
-
Access to the article
- Get it from the cache. If not, get it from the database and store it in the cache.
- Update browse count list
article:list:sort:views
. - Update the cache.
-
Update the article
- use
redisLockUtil
(custom tool class) lock, place concurrent conditions for uniform article update. - Update the cache.
- Update the latest list (update time score).
- Releases the lock.
- use
-
Delete articles
- Delete the database.
- Delete the cache. Includes: update time list
article:list:sort:updateTime
, article listarticle:list:all
, a list of likesarticle:list:sort:views
, and the corresponding article key-value pairsarticle:list:all:xxx
).
Redis database diagram:
\