Home > Database > Redis > body text

Share redis multi-dimensional ranking ideas

藏色散人
Release: 2023-04-21 16:01:59
forward
1188 people have browsed it

This article brings you relevant knowledge about redis. It mainly shares with you the idea of ​​redis multi-dimensional ranking. Friends who are interested can take a look at it together. I hope it will be helpful to everyone.

Share redis multi-dimensional ranking ideas

Problem Description

  1. #As we all know, redis zset is often used in rankings and can be done right out of the box Use it, but it has a disadvantage, that is, it only supports single-dimensional rankings.

  2. However, in actual projects, single-dimensional ranking is indeed very impractical. A simple example is walking ranking. The product requirement is to rank and sort based on the number of steps, completion time, and person’s name. Priority is from left to right.

  3. My solution is to convert all dimensions into numbers, and then add the numbers in these dimensions, so that multi-dimensional rankings can be solved.

Specific solution ideas

  1. Number of steps: Originally it is a number and can be ignored

  2. Completion time: The completion time generally stores a timestamp, and the later the timestamp is, the larger the value will be. To ensure that the earlier the completion time is, the higher the ranking will be. The earlier the time is, the greater the value will be. We can subtract the timestamp of the user's completion time from a larger timestamp, so that the earlier the completion time, the greater the value.
  3. Personal names: Personal names are generally composed of Chinese characters or letters. Chinese characters and letters are both strings. When we want to sort, the first step is to convert the strings into numbers. It is recommended to use PHP for this process. Native function mb_ord.

  4. For example, the number of steps of a user is 10,000, the completion time (after calculation) is 100,000 (a timestamp written randomly), and the name of the person is 500 (after calculation) is Zhang San (written randomly) ), we can get a value of 10000.100500 (number of steps, completion time and person name added together).
  5. In the actual process of obtaining the value, we can remove the decimal point. The number after the decimal point is only used for ranking.

    Recommended learning: "Redis Video Tutorial"

The above is the detailed content of Share redis multi-dimensional ranking ideas. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!