I need some help with my logic/approach please. I am wanting to create a gaming server list. So people can add their server by entering in
我需要一些关于我的逻辑/方法的帮助。我想创建一个游戏服务器列表。所以人们可以通过输入来添加他们的服务器
title, IP, port, about.
However on the homepage I also want to display how many players and whether it is online or not. If its offline I dont want to display it. Now for this I can query an api which returns a string like.
但是在主页上我还想显示有多少玩家以及是否在线。如果它离线我不想显示它。现在我可以查询一个返回字符串的api。
{"players_online":22,"max_players":150,"gametype":"TNT"}
These values will change every 60 seconds usually.
这些值通常每60秒更改一次。
What is the best approach to merge the 2 together? I want to store the server basic info in the db but things like players_online and whether the server is up needs to be checked at least every 60 seconds.
将2合并在一起的最佳方法是什么?我想将服务器基本信息存储在数据库中,但是诸如players_online之类的内容以及服务器是否启动需要至少每隔60秒检查一次。
1 个解决方案
#1
2
As per my experience combining both will result in big mesh, I suggest would suggest following:
根据我的经验,结合两者将导致大网格,我建议建议如下:
Job 1: Update all your user's active status, potentially you can have a CRON job that will check if your user is on-line or not and update the Database (I would nor recommend this, rather use some cache and update that cache periodically).
作业1:更新所有用户的活动状态,可能有一个CRON作业将检查您的用户是否在线并更新数据库(我不建议这样做,而是使用一些缓存并定期更新该缓存) 。
Job 2: Create schema that will make less query to database
作业2:创建将减少对数据库的查询的模式
gameId -> gameName -> gammerId
1 -> NFS -> g01
1 -> NFS -> g02
2 -> CS -> g01
or (my recommended schema)
或(我推荐的架构)
gameId -> gameName -> listOfGammers
1 -> NFS -> g01, g02, g03
2 -> CS -> g02, g05
In this way you make less query on your database, if you have 100 users in single game you can still get all the gammerIds in signle row + you already have list of users which are online from the cache.
通过这种方式,您可以减少对数据库的查询,如果您在单个游戏中有100个用户,您仍然可以获得符号行中的所有gammerId +您已经拥有从缓存中联机的用户列表。
Hope that helps
希望有所帮助
#1
2
As per my experience combining both will result in big mesh, I suggest would suggest following:
根据我的经验,结合两者将导致大网格,我建议建议如下:
Job 1: Update all your user's active status, potentially you can have a CRON job that will check if your user is on-line or not and update the Database (I would nor recommend this, rather use some cache and update that cache periodically).
作业1:更新所有用户的活动状态,可能有一个CRON作业将检查您的用户是否在线并更新数据库(我不建议这样做,而是使用一些缓存并定期更新该缓存) 。
Job 2: Create schema that will make less query to database
作业2:创建将减少对数据库的查询的模式
gameId -> gameName -> gammerId
1 -> NFS -> g01
1 -> NFS -> g02
2 -> CS -> g01
or (my recommended schema)
或(我推荐的架构)
gameId -> gameName -> listOfGammers
1 -> NFS -> g01, g02, g03
2 -> CS -> g02, g05
In this way you make less query on your database, if you have 100 users in single game you can still get all the gammerIds in signle row + you already have list of users which are online from the cache.
通过这种方式,您可以减少对数据库的查询,如果您在单个游戏中有100个用户,您仍然可以获得符号行中的所有gammerId +您已经拥有从缓存中联机的用户列表。
Hope that helps
希望有所帮助