Created
April 2, 2015 02:56
-
-
Save zhwei/6befd5afa5e89338d5d0 to your computer and use it in GitHub Desktop.
AsyncRedis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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