Now we are going to make a game product that involves scoring rankings. Simple ranking can be done with redis sortset. But how should we design dynamic ranking? For example, the monthly ranking is actually the ranking from the current time to the past 30 days, because time is time changing, so the time dimension... now I want to build a game product that involves scoring rankings,
Simple ranking can be completed using redis's sort set,
But how should we design dynamic rankings?
For example, the monthly ranking is actually the ranking from the current time to the past 30 days,
Because time is time changing, the time dimension changes every second.
Answer the question from lan Hao.
It is a game. It generally takes 10-40 seconds to play a game,
When the game is finished, there will be a score,
Now, monthly ranking is required (from now till 30*24*3600 seconds ago ),
If a person plays for multiple times, the best score is used for statistics.
Reply content:
Now I want to build a game product that involves scoring rankings,
Simple ranking can be completed using redis's sort set,
But how should we design dynamic rankings?
For example, the monthly ranking is actually the ranking from the current time to the past 30 days,
Because time is time changing, the time dimension changes every second.
Answer the question from lan Hao.
It is a game. It generally takes 10-40 seconds to play a game,
When the game is finished, there will be a score,
Now, monthly ranking is required (from now till 30*24*3600 seconds ago ),
If a person plays for multiple times, the best score is used for statistics.
Let me help you.
Also usedZSET
For example, adding points to a user's victory:
Zincrby day: 20150113 60 KavlezZINCRBY DAY: 20150113 80 dance qianxun
Like this, it is a ZSET every day.
However, if you count up to 30 days, it will always be 30.DEL
One.
Update ZSET every day (or several minutes) for the last 30 days:
ZUNIONSTORE LAST30 2 LAST30 DAY:20150113
Top 10:
ZREVRANGE LAST30 0 10 WITHSCORES
Try it.socket.io
This is to maintain a persistent connection. With a persistent connection, everything can be done 〜
Suitable for mongodb
Each score is counted as a record (document), added with a timestamp, saved
Aggregate takes care of the Score list
Since it is a real-time list, you can update it in real time.ZSET
OfSCORE
You can.
As for your ranking over the last 30 days, I think you are talking about the ranking over the last 30 days of point growth.
Product logic referencesegmentfault
"List", The implementation method is to useZSET
Record the growth of user points every day, so that weekly, monthly, quarterly, and annual lists can be usedZUNIONSTORE
.
I have made several game rankings and explained my ideas.
Rankings are divided by Time:
- Historical ranking. The so-called historical ranking indicates that the Score data has been solidified and the data cannot be changed again. For example, monthly or weekly ranking.
- Real-time ranking. The latest ranking of data is still changing.
Players generally have two concerns:
- Data of the First N names, for example, data of the first 100.
- Your ranking and the number of players with the top N or bottom ranking.
Based on the 2.1 above, the ranking data will be divided into two parts:
- The first N data is stored in a single table. The data in this table is small, frequently updated, and the data is very real-time.
- Converts a score to a stage, for example, 10 points for a stage. Record the number of people in each stage and the first N people in each stage.
I don't know.
Try it.Meteor
Framework is based onnodejs
Andmongodb
OfWebApp
Framework, throughDDP
Protocol to process real-time communication. Real-Time Code Update. After the server code is updated, the client does not need user intervention. In addition, there is a delayed synchronization mechanism. The user submits real-time data feedback on the screen. If the data submission fails due to network reasons, the data will be uploaded after the network reconnects.
Meteor Official Website
What about density? First, we need to clarify your ranking.