diff --git a/f7/__init__.py b/f7/__init__.py index 3529911..1bf49cf 100644 --- a/f7/__init__.py +++ b/f7/__init__.py @@ -12,3 +12,23 @@ timer = i_timer() def isOnlineEnv(): return not os.getenv("SERVER_ENV"); + +def scanRedisKey(conn, pattern): + result = {} + cursor, keys = conn.scan(0, pattern, 1000) + while cursor != 0 or len(keys) > 0: + for key in keys: + if key in result: + result[key] += result[key] + else: + result[key] = 0 + keys = [] + if cursor != 0: + cursor, keys = conn.scan(cursor, pattern, 1000) + return result + +def getChannelByAccountId(account_id): + tmp_strings = account_id.split('_') + if len(tmp_strings) < 3: + return 0 + return tmp_strings[0] diff --git a/f7/app.py b/f7/app.py index 23d2df3..b113d36 100644 --- a/f7/app.py +++ b/f7/app.py @@ -42,6 +42,9 @@ class _App: def callAt(self, when, callback): tornado.ioloop.IOLoop.current().call_at(when, callback) + def callLater(self, when, callback): + tornado.ioloop.IOLoop.current().call_later(when, callback) + def registerHandler(self, c, a, callback): self._requestHandler[c + '$' + a] = callback diff --git a/f7/timer.py b/f7/timer.py index 01f4646..b92697e 100644 --- a/f7/timer.py +++ b/f7/timer.py @@ -18,5 +18,8 @@ class _Timer: def callAt(self, when, callback): f7.app.callAt(when, callback) + def callLater(self, when, callback): + f7.app.callLater(when, callback) + def instance(): return _Timer.instance()