Skip to content

Instantly share code, notes, and snippets.

@zhwei
Created April 2, 2015 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhwei/6befd5afa5e89338d5d0 to your computer and use it in GitHub Desktop.
Save zhwei/6befd5afa5e89338d5d0 to your computer and use it in GitHub Desktop.
AsyncRedis
import tornadoredis
class AsyncRedis(Redis):
CONNECTION_POOLS = {}
@classmethod
def get_conn(cls, name='DEFAULT'):
host, port, db = cls._get_config(name)
key = '{}:{}'.format(host, port)
pool = cls.CONNECTION_POOLS.get(key)
if not pool:
pool = tornadoredis.ConnectionPool(
max_connections=10, wait_for_available=True, # ConnectionPool kwargs
host=host, port=port, # Connection kwargs
)
cls.CONNECTION_POOLS[key] = pool
return tornadoredis.Client(connection_pool=pool, selected_db=db)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment