[Server | Redis] How to use redis ordered collection to implement the order list of stock trading (price priority, time priority)

When I was messing around with redis' ordered collections two days ago , I discovered a problem. How are redis's ordered collections sorted when the scores are the same?

Through Google search, I found some clues. When the scores are the same, redis uses dictionary sorting. However, I don’t quite understand what dictionary sorting is, so I tested it myself. I believe the screenshot below can answer this question:

When the scores are the same, redis uses dictionary sorting, and the so-called dictionary sorting is actually sorting like "ABCDEFG". When the first letters are the same, redis will compare the following letters and still sort according to the dictionary (as shown in the screenshot) Indicates the order of beigai and baijing).

According to the above figure, we can format the price and set it to score, format the timestamp and order amount and merge them into one field. Keep the format of this field in all orders the same, and redis will automatically sort user transactions through the dictionary.

Guess you like

Origin blog.csdn.net/qq_28505809/article/details/133269729