Skip to content

Instantly share code, notes, and snippets.

@ityoung
Last active May 22, 2019 07:26
Show Gist options
  • Save ityoung/cf6f561da66a32a09744ecf17bfb9d82 to your computer and use it in GitHub Desktop.
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