async def hscan(self, str_key, cursor=0, match=None, count=None, mod='redis'): conn = Redis.conn(str_key, mod) return conn.hscan(str_key, cursor, match, count)
async def zrange(self, str_key, begin, end, withscore=False, score_cast_func=float, mod='redis'): conn = Redis.conn(str_key, mod) return conn.zrange(str_key, begin, end, withscore, score_cast_func)
async def set(self, str_key, value, ex=None, px=None, nx=False, xx=False, mod='redis'): conn = Redis.conn(str_key, mod) return conn.set(str_key, value, ex, px, nx, xx)
from common import Db, Redis from route import route from tornado.gen import coroutine from tornado.concurrent import Future def hello_timer(): # print("hello timer") pass if __name__ == "__main__": settings = { 'debug': True, "cookie_secret": "__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__", } app = tornado.web.Application(route, **settings) # app = make_app() app.listen(8000) Db.instance() # 初始化db连接池 Redis.init() # 初始化redis连接池 iol = tornado.ioloop.IOLoop.current() # 定时器 毫秒为单位 tornado.ioloop.PeriodicCallback( hello_timer, 1000 ).start() print('app start on', 8000) iol.start()
async def sadd(self, str_key, field, mod='redis'): conn = Redis.conn(str_key, mod) return conn.sadd(str_key, field)
async def zincry(self, str_key, field, add, mod='redis'): conn = Redis.conn(str_key, mod) return conn.zincrby(str_key, field, add)
async def zset(self, str_key, mod='redis', *argvs, **kwargs): conn = Redis.conn(str_key, mod) return conn.zadd(str_key, *argvs, **kwargs)
async def expire(self, str_key, expire, mod='redis'): conn = Redis.conn(str_key, mod) return conn.expire(str_key, expire)
async def get(self, str_key, mod='redis'): conn = Redis.conn(str_key, mod) return conn.get(str_key)
async def hmget(self, str_key, fields, mapping, mod='redis'): conn = Redis.conn(str_key, mod) return conn.hmget(str_key, fields, mapping)
async def hset(self, str_key, filed, value, mod='redis'): conn = Redis.conn(str_key, mod) return conn.hset(str_key, filed, value)
async def hgetall(self, str_key, mod='reids'): conn = Redis.conn(str_key, mod) return conn.hgetall(str_key)
async def hget(self, str_key, filed, mod='redis'): conn = Redis.conn(str_key, mod) return conn.hget(str_key, filed)
async def srem(self, str_key, *values, mod='redis'): conn = Redis.conn(str_key, mod) return conn.srem(str_key, *values)
async def smembers(self, str_key, mod='redis'): conn = Redis.conn(str_key, mod) return conn.smembers(str_key)
async def sismember(self, str_key, field, mod='redis'): conn = Redis.conn(str_key, mod) return conn.sismember(str_key, field)