Skip to content

Instantly share code, notes, and snippets.

@ityoung
Last active May 22, 2019 07:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ityoung/cf6f561da66a32a09744ecf17bfb9d82 to your computer and use it in GitHub Desktop.
import aioredis
class MyRedis(object):
_redis = None
@classmethod
async def redis(cls):
if not cls._redis:
cls._redis = await aioredis.create_redis('redis://localhost')
return cls._redis
from tornado.web import RequestHandler
from redis-singleton import MyRedis
class MyHandler(RequestHandler):
async def get(self):
id = self.request.arguments.get('id', None)
self.redis = await MyRedis.redis()
await self.redis.set(id, json.dumps({"status": 0}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment