diff --git a/handlers/apiOnlineUsersHandler.py b/handlers/apiOnlineUsersHandler.py index a35a6ed..209c59d 100644 --- a/handlers/apiOnlineUsersHandler.py +++ b/handlers/apiOnlineUsersHandler.py @@ -10,7 +10,7 @@ class handler(requestsManager.asyncRequestHandler): data = {"message": "unknown error"} try: # Get online users count - data["result"] = len(glob.tokens.tokens) + data["result"] = int(glob.redis.get("ripple:online_users").decode("utf-8")) # Status code and message statusCode = 200 diff --git a/objects/tokenList.py b/objects/tokenList.py index e7b486b..fd23d54 100644 --- a/objects/tokenList.py +++ b/objects/tokenList.py @@ -24,6 +24,7 @@ class tokenList: """ newToken = osuToken.token(userID, ip=ip, irc=irc, timeOffset=timeOffset, tournament=tournament) self.tokens[newToken.token] = newToken + glob.redis.incr("ripple:online_users") return newToken def deleteToken(self, token): @@ -34,12 +35,10 @@ class tokenList: :return: """ if token in self.tokens: - # Delete session from DB if self.tokens[token].ip != "": userUtils.deleteBanchoSessions(self.tokens[token].userID, self.tokens[token].ip) - - # Pop token from list self.tokens.pop(token) + glob.redis.decr("ripple:online_users") def getUserIDFromToken(self, token): """ diff --git a/pep.py b/pep.py index eb2ca4c..83dce3d 100644 --- a/pep.py +++ b/pep.py @@ -115,6 +115,7 @@ if __name__ == "__main__": # Empty redis cache try: # TODO: Make function or some redis meme + glob.redis.set("ripple:online_users", 0) glob.redis.eval("return redis.call('del', unpack(redis.call('keys', ARGV[1])))", 0, "peppy:*") except redis.exceptions.ResponseError: # Script returns error if there are no keys starting with peppy:*