Return a redis.Redis instance connected to REDIS_URL.
776822
def create_connection():
    """"""
    # REDIS_URL is defined in .env and loaded into the environment by Honcho
    redis_url = os.getenv('REDIS_URL')
    # If it's not defined, use the Redis default
    if not redis_url:
        redis_url = 'redis://localhost:6379'
    urlparse.uses_netloc.append('redis')
    url = urlparse.urlparse(redis_url)
    return redis.StrictRedis(
        host=url.hostname,
        port=url.port,
        db=0,
        password=url.password
    )
820786
def get_logout_url(self, redirect_url=None):
        """"""
        url = urllib_parse.urljoin(self.server_url, 'logout')
        if redirect_url:
            params = {self.logout_redirect_param_name: redirect_url}
            url += '?' + urllib_parse.urlencode(params)
        return url
1166982
def hlen(self, name):
        
        with self.pipe as pipe:
            return pipe.hlen(self.redis_key(name))
771425
def redis_info url, password
      begin
        r = Redis.new url: url, password: password
        info = r.info.merge 'dbsize' => r.dbsize
      rescue Exception => e
        STDERR.puts "[ERROR][#{__FILE__}:#{__LINE__}] Failed to get data from Redis - " +
          "#{url.inspect} (using password #{password.inspect}): #{e.message}\n#{e.backtrace.join("\n")}"
        return {}
      end

      begin
        info['maxmemory'] = @options.fetch(:max_memory) { r.config(:get, 'maxmemory')['maxmemory'] }
      rescue Exception
        info['maxmemory'] = info['used_memory_rss']
      end

      r.quit

      {
        'connections'     => info['connected_clients'].to_i,
        'used_memory'     => info['used_memory'].to_f,
        'used_memory_rss' => info['used_memory_rss'].to_f,
        'fragmentation'   => info['mem_fragmentation_ratio'].to_f,
        'expired_keys'    => info['expired_keys'].to_i,
        'evicted_keys'    => info['evicted_keys'].to_i,
        'hits'            => info['keyspace_hits'].to_i,
        'misses'          => info['keyspace_misses'].to_i,
        'keys'            => info['dbsize'].to_i,
        'max_memory'      => info['maxmemory'].to_i,
        'hit_ratio'       => 0
      }.tap {|d| d['hit_ratio'] = d['hits'].to_f / (d['hits']+d['misses']).to_f if d['hits'] > 0 }
    end
801044
def redis(self):
        
        redis_url = current_app.config.get("SSE_REDIS_URL")
        if not redis_url:
            redis_url = current_app.config.get("REDIS_URL")
        if not redis_url:
            raise KeyError("Must set a redis connection URL in app config.")
        return StrictRedis.from_url(redis_url)
1326881
def _get_serv(ret=None):
    '''
    
    '''
    _options = _get_options(ret)
    global REDIS_POOL
    if REDIS_POOL:
        return REDIS_POOL
    elif _options.get('cluster_mode'):
        REDIS_POOL = StrictRedisCluster(startup_nodes=_options.get('startup_nodes'),
                                        skip_full_coverage_check=_options.get('skip_full_coverage_check'),
                                        decode_responses=True)
    else:
        REDIS_POOL = redis.StrictRedis(host=_options.get('host'),
                                       port=_options.get('port'),
                                       unix_socket_path=_options.get('unix_socket_path', None),
                                       db=_options.get('db'),
                                       decode_responses=True,
                                       password=_options.get('password'))
    return REDIS_POOL
905525
def fetch(self):
        
        raw = yield gen.Task(self._redis_client.get, self._key)
        if raw:
            self.loads(base64.b64decode(raw))
            raise gen.Return(True)
        raise gen.Return(False)
586161
def _client(self, host, port, unix_socket, auth):
        
        db = int(self.config['db'])
        timeout = int(self.config['timeout'])
        try:
            cli = redis.Redis(host=host, port=port,
                              db=db, socket_timeout=timeout, password=auth,
                              unix_socket_path=unix_socket)
            cli.ping()
            return cli
        except Exception as ex:
            self.log.error("RedisCollector: failed to connect to %s:%i. %s.",
                           unix_socket or host, port, ex)
153529
def redis_version(self):
        """"""
        if not hasattr(self, '_redis_version'):
            self._redis_version = tuple(
                map(int, self.connection.info().get('redis_version').split('.')[:3])
            )
        return self._redis_version
996703
def resource_url(self):
        """"""
        if self._iam:
            self._resource_url = self._resource_url or _get_iam_rest_api_url_from_creds(self.rest_client, self.credentials)
        else:
            self._resource_url = self._resource_url or _get_rest_api_url_from_creds(self.session, self.credentials)
        return self._resource_url
58809
function() {
      return Promise.retry(function() {
        log.debug(format('Connecting to redis on %s:%s', REDIS_IP, REDIS_PORT));
        return redis.createClient(REDIS_PORT, REDIS_IP);
      });
    }
1106503
def _internal_kv_get(key):
    """"""

    worker = ray.worker.get_global_worker()
    if worker.mode == ray.worker.LOCAL_MODE:
        return _local.get(key)

    return worker.redis_client.hget(key, "value")
805990
def llen(self, name):
        
        with self.pipe as pipe:
            return pipe.llen(self.redis_key(name))
699653
def get_redis_connection():
    
    if config.MOCK_REDIS:  # pragma: no cover
        import mockredis
        return mockredis.mock_strict_redis_client()  # pragma: no cover
    elif config.DEFENDER_REDIS_NAME:  # pragma: no cover
        try:
            cache = caches[config.DEFENDER_REDIS_NAME]
        except InvalidCacheBackendError:
            raise KeyError(INVALID_CACHE_ERROR_MSG.format(
                config.DEFENDER_REDIS_NAME))
        # every redis backend implement it own way to get the low level client
        try:
            # redis_cache.RedisCache case (django-redis-cache package)
            return cache.get_master_client()
        except AttributeError:
            # django_redis.cache.RedisCache case (django-redis package)
            return cache.client.get_client(True)
    else:  # pragma: no cover
        redis_config = parse_redis_url(config.DEFENDER_REDIS_URL)
        return redis.StrictRedis(
            host=redis_config.get('HOST'),
            port=redis_config.get('PORT'),
            db=redis_config.get('DB'),
            password=redis_config.get('PASSWORD'),
            ssl=redis_config.get('SSL'))
1195697
def get(key, profile=None):
    '''
    
    '''
    if not profile:
        return False
    redis_kwargs = profile.copy()
    redis_kwargs.pop('driver')
    redis_conn = redis.StrictRedis(**redis_kwargs)
    return redis_conn.get(key)
1085354
def get_redis_connection(config, use_strict_redis=False):
    
    redis_cls = redis.StrictRedis if use_strict_redis else redis.Redis

    if 'URL' in config:
        return redis_cls.from_url(config['URL'], db=config.get('DB'))

    if 'USE_REDIS_CACHE' in config.keys():

        try:
            # Assume that we're using django-redis
            from django_redis import get_redis_connection as get_redis
            return get_redis(config['USE_REDIS_CACHE'])
        except ImportError:
            pass

        from django.core.cache import caches
        cache = caches[config['USE_REDIS_CACHE']]
        # We're using django-redis-cache
        try:
            return cache._client
        except AttributeError:
            # For django-redis-cache > 0.13.1
            return cache.get_master_client()

    if 'UNIX_SOCKET_PATH' in config:
        return redis_cls(unix_socket_path=config['UNIX_SOCKET_PATH'], db=config['DB'])

    if 'SENTINELS' in config:
        sentinel_kwargs = {
            'db': config.get('DB'),
            'password': config.get('PASSWORD'),
            'socket_timeout': config.get('SOCKET_TIMEOUT'),
        }
        sentinel_kwargs.update(config.get('CONNECTION_KWARGS', {}))
        sentinel = Sentinel(config['SENTINELS'], **sentinel_kwargs)
        return sentinel.master_for(
            service_name=config['MASTER_NAME'], redis_class=redis_cls,
        )

    return redis_cls(host=config['HOST'], port=config['PORT'], db=config['DB'], password=config.get('PASSWORD'), ssl=config.get('SSL', False))
63006
def get_connection(self, internal=False):
        
        # Determine the connection string to use.
        connect_string = self.connect_string
        if internal:
            connect_string = self.internal_connect_string

        # Stripe Redis protocol prefix coming from the API.
        connect_string = connect_string.strip('redis://')
        host, port = connect_string.split(':')

        # Build and return the redis client.
        return redis.StrictRedis(host=host, port=port, password=self._password)