Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - The score of redis zset is modified to 64-bit shaping, which supports the snowflake ID algorithm.
The score of redis zset is modified to 64-bit shaping, which supports the snowflake ID algorithm.
There are many articles about the snowflake ID algorithm, so I won't gild the lily. Of course, the Snowflake ID algorithm also has a time callback problem, which can be understood by referring to the following two links:

/baidu/uid-generator

/p/77737855

However, when we save this 64-bit ID in the zset of redis, we will face the overflow problem of the score of the zset, because the score is a 64-bit double type (float64), and some developers have proposed a solution to this problem. See:/developer/article/1525534 for details.

The same point of their solution is to change the Snowflake ID to 52 bits (the integer precision of float64 is 52 bits) in order not to overflow, but this will inevitably lead to a smaller range of ID. For example, their business is to save messages 15 days. This modification is not an implementation that meets complex business scenarios. In 20 years and 2 1 year, the source code of redis server was modified intermittently, the score type was changed from float64 to int64, and the client interfaces of php redis and Goridis were also modified simultaneously. Because it is used in the company's emerging business, the source code cannot be made public without the company's consent, and it is not difficult to modify it.