.BANCHO. Move online users count to redis
This commit is contained in:
parent
525235a27e
commit
5723c0e68f
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
1
pep.py
1
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:*
|
||||
|
|
Loading…
Reference in New Issue
Block a user