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

    1. Create it in the database

    2. Deposited in the redis

      1. The key forArticle :list:all: + article ID, value indicates the value json
      2. The latest list is stored in Redis, sorted set (ZSET) is used, and score is the update time stamp of the article.
      3. In redis, the sorted set (ZSET) is used to store the list, and score is used to create the timestamp of the article.
  • Get the list of articles

    1. througharticle:list:sort:createTimeGets a list of article ids, sorted by creation time.
    2. throughredisTemplate.opsForValue().multiGetGet the List of articles and return it to the front end as a new List with the key passed in (handwritten for paging).
  • Get the latest list

    1. througharticle:list:sort:updateTimeGets a list of the most recent article ids (sorted by update time).
    2. throughredisTemplate.opsForValue().multiGetGet the List of articles and return it to the front end as a new List with the key passed in (handwritten for paging).
  • Access to the article

    1. Get it from the cache. If not, get it from the database and store it in the cache.
    2. Update browse count listarticle:list:sort:views.
    3. Update the cache.
  • Update the article

    1. useredisLockUtil(custom tool class) lock, place concurrent conditions for uniform article update.
    2. Update the cache.
    3. Update the latest list (update time score).
    4. Releases the lock.
  • Delete articles

    1. Delete the database.
    2. Delete the cache. Includes: update time listarticle: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:

\