def __init__(self, *args, **kwargs): redis = get_cache_redis() if redis is None: self.cache = _Cache(*args, **kwargs) else: assert Redis is not None, 'Packages needed by Redis are missing' self.cache = Redis(*args, **kwargs)
def ensure_client(cls): with cls._client_check_lock: if cls._client is None: redis_url = get_cache_redis() url = urlparse(redis_url) assert url.scheme == 'redis', 'invalid redis url' host = url.hostname port = url.port db = url.path.strip('/') cls._client = redis.StrictRedis(host=host, port=port, db=db)
def start(): if os.environ.get('WSGI_LOG_FILE'): global broker global listener logger.info('init_pool: start on %s', os.getpid()) if broker: logger.warning('init_pool: already started on %s', os.getpid()) return redis_url = get_cache_redis() if redis_url: url = urlparse(redis_url) assert url.scheme == 'redis', 'invalid redis url' host = url.hostname port = url.port db = url.path.strip('/') broker = redis.StrictRedis(host=host, port=port, db=db) listener = Listener(broker, {'init_pool': init_pool_cb}) listener.start()