About the Design of redis ranking with millions of users

1. If you want to make a ranking of users" gold coins, only the highest 100 records will be displayed if displayed.
2. When it comes to using redis to do the ranking, most people will think of using sorted set to do it. But if there are millions of users and hundreds of thousands of daily active users, it would be a bit too much to put all the data on redis.
3. Is it reasonable to store the user"s information in the database first, update all the operations on the database, and then regularly take out 100 pieces of data from the database and put them in sorted zet for users to read? This reduces memory consumption and redis server write operations
4. On the other hand, how to consider whether the amount of data is too large or the IO operation is too frequent to be put on the redis?

Mar.10,2021

because you only need to display the top 100, you can use a minimum heap.

Redi can save the 100th score with sorted set plus a key. After updating the user's score in the database, first determine whether it is higher than the current 100th. If so, update key and insert / update to sorted set, and then regularly remove the 100th, so that it will not take up too much memory.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf52c3-31f66.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf52c3-31f66.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?