python类Redis()的实例源码

test_accuracy.py 文件源码 项目:pyreBloom-ng 作者: leovp 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def test_size_allocation(self):
        """Make sure we can allocate a bloom filter that would take more than
        512MB (the string size limit in Redis)"""
        included = sample_strings(20, 5000)
        excluded = sample_strings(20, 5000)

        # Add only the included strings
        self.bloom.update(included)
        self.assertEqual(len(included), len(self.bloom.intersection(included)))

        false_positives = self.bloom.intersection(excluded)
        false_rate = float(len(false_positives)) / len(excluded)
        self.assertTrue(false_rate <= 0.00001,
                        'False positive error rate exceeded!')

        # We also need to know that we can access all the keys we need
        self.assertEqual(self.bloom.keys(),
                         [b'pyreBloomTesting.0', b'pyreBloomTesting.1'])
cache.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
__init__.py 文件源码 项目:automatron 作者: madflojo 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def connect(self):
        ''' Open Connection to Redis '''
        if "password" not in self.config['datastore']['plugins']['redis'].keys():
            password = None
        else:
            password = self.config['datastore']['plugins']['redis']['password']
        try:
            self.dbc = redis.Redis(
                host=self.config['datastore']['plugins']['redis']['host'],
                port=self.config['datastore']['plugins']['redis']['port'],
                password=None,
                db=self.config['datastore']['plugins']['redis']['db'])
        except Exception as e:
            raise Exception("Failed to connect to Redis: {0}".format(e.message))
        self.initialize_db()
        return True
cache.py 文件源码 项目:swjtu-pyscraper 作者: Desgard 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
cache.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
cache.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
cache.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
cache.py 文件源码 项目:harbour-sailfinder 作者: DylanVanAssche 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
cache.py 文件源码 项目:harbour-sailfinder 作者: DylanVanAssche 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
redis_wrapper.py 文件源码 项目:sci-pype 作者: jay-johnson 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def exists(self, key):
        ############################################################################################
        # START common safety net for high availability connectivity handling
        # This class will automatically retry connections for Redis Instances that are not available
        success = False
        while not success:
            try:
        # END common safety net for high availability connectivity handling
        ############################################################################################

                return self.m_redis.exists(key)

        ############################################################################################
        # START common safety net for high availability connectivity handling
                success = True
            except Exception,R:
                # try to reconnect with a throttle
                self.retry_throttled_connection(R)
            # end try/ex
        # end of while not successful
        # END common safety net for high availability connectivity handling
        ############################################################################################

    # end of exists
cache.py 文件源码 项目:Texty 作者: sarthfrey 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
queues.py 文件源码 项目:DCRM 作者: 82Flex 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def get_queues(*queue_names, **kwargs):
    """
    Return queue instances from specified queue names.
    All instances must use the same Redis connection.
    """
    from .settings import QUEUES
    autocommit = kwargs.get('autocommit', None)
    queue_class = kwargs.get('queue_class', DjangoRQ)
    if len(queue_names) == 0:
        # Return "default" queue if no queue name is specified
        return [get_queue(autocommit=autocommit)]
    if len(queue_names) > 1:
        queue_params = QUEUES[queue_names[0]]
        connection_params = filter_connection_params(queue_params)
        for name in queue_names:
            if connection_params != filter_connection_params(QUEUES[name]):
                raise ValueError(
                    'Queues must have the same redis connection.'
                    '"{0}" and "{1}" have '
                    'different connections'.format(name, queue_names[0]))
    return [get_queue(name, autocommit=autocommit, queue_class=queue_class) for name in queue_names]
test_connection.py 文件源码 项目:micropython-redis 作者: dwighthubbard 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def test_auth(self):
        redis_server = redislite.Redis(
            serverconfig={
                'requirepass': 'test',
                'port': self.redis_test_port+1
            },
            password='test'
        )


        # This shouldn't generate an exception
        try:
            redis_client = redis.Redis(host='127.0.0.1', port=self.redis_test_port+1, password='test')
            uredis_client = uredis.Redis(host='127.0.0.1', port=self.redis_test_port+1, password='test')
        finally:
            redis_server.shutdown()
oauth.py 文件源码 项目:wank.party 作者: Streetwalrus 项目源码 文件源码 阅读 45 收藏 0 点赞 0 评论 0
def authorize_POST():
    client_id = request.form.get("client_id")
    if not client_id:
        return render_template("oauth-authorize.html", errors="Missing client_id")
    client = OAuthClient.query.filter(OAuthClient.client_id == client_id).first()
    if not client:
        abort(404)
    salt = os.urandom(40)
    code = hashlib.sha256(salt).hexdigest()[:10]
    r = redis.Redis()
    r.setex("oauth.exchange.client." + code, client_id, 600) # expires in 10 minutes
    r.setex("oauth.exchange.user." + code, current_user.id, 600)
    params = {
        "code": code
    }
    parts = list(urllib.parse.urlparse(client.redirect_uri))
    parsed = urllib.parse.parse_qs(parts[4])
    parsed.update(params)
    parts[4] = urllib.parse.urlencode(parsed)
    return redirect(urllib.parse.urlunparse(parts))
cache.py 文件源码 项目:tesismometro 作者: joapaspe 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
__init__.py 文件源码 项目:dictator 作者: dictatorlib 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def set(self, key, value):
        """Set the value at key ``key`` to ``value``

        >>> dc = Dictator()
        >>> dc['s0'] = 'string value'
        >>> dc['s0']
        'string value'
        >>> dc.set('l0', ['abc', 123])
        >>> dc['l0']
        ['abc', '123']
        >>> dc.set([1, 2, 3], ['a', 'b'])
        >>> dc['[1, 2, 3]']
        ['a', 'b']
        >>> dc.clear()

        :param key: any value (will be converted to string in Redis)
        :type key: Any
        :param value: Any
        :return: None
        :rtype None
        """
        self.__setitem__(key, value)
redis_test.py 文件源码 项目:base_function 作者: Rockyzsu 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def base_usage():
    print r.dbsize()
    #r.flushdb()
    print r.dbsize()
    print r.exists('house')
    #r = redis.Redis(host='183.232.57.39', port=7001, db=0,password='jiguang')

    for i in range(10):
        r.set(i,i)
        #????????

    for i in range(10):
        x=r.get(i)
        print x
        print type(x)
    #print r.get('test')

#?????
rcwatcher.py 文件源码 项目:embeddeddata 作者: toolforge 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def run_watcher():
    site = pywikibot.Site(user="Embedded Data Bot")
    redis = Redis(host="tools-redis")

    signal.signal(signal.SIGALRM, on_timeout)
    signal.alarm(TIMEOUT)

    rc = site_rc_listener(site)
    for change in rc:
        signal.alarm(TIMEOUT)

        if (
            change['type'] == 'log' and
            change['namespace'] == 6 and
            change['log_type'] == 'upload'
        ):
            redis.rpush(REDIS_KEY, json.dumps(change))

    pywikibot.output("Exit - THIS SHOULD NOT HAPPEN")
cache.py 文件源码 项目:RPoint 作者: george17-meet 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
cache.py 文件源码 项目:isni-reconcile 作者: cmh2166 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
cache.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
Task.py 文件源码 项目:opsweb 作者: wylok 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def zabbix_api_lvs():
    try:
        t = time.strftime('%H',time.localtime())
        tm = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
        Key = 'lvs_internet'
        Key1 = 'lvs_intranet'
        if t == '00':
            Redis.delete(Key)
            Redis.delete(Key1)
        key='lvs[80]'
        history = 3
        method = 'history.get'
        host = '172.16.16.8'
        v8 = zabbix_api.GET_value(host,key,method,history)
        host = '172.16.16.4'
        v4 = zabbix_api.GET_value(host,key,method,history)
        host = '172.16.16.5'
        v5 = zabbix_api.GET_value(host,key,method,history)
        if v4 and v8:
            lvs_conn = int(v4)+int(v8)
            Redis.lpush(Key,[tm,lvs_conn])
        if v5:
            Redis.lpush(Key1,[tm,int(v5)])
    except Exception as e:
        logging.error(e)
cache.py 文件源码 项目:RealtimePythonChat 作者: quangtqag 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
redis_session.py 文件源码 项目:spc 作者: whbrewer 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self, server='localhost:6379', db=None, debug=False,
            session_expiry=False, with_lock=False, password=None):
        """session_expiry can be an integer, in seconds, to set the default expiration
           of sessions. The corresponding record will be deleted from the redis instance,
           and there's virtually no need to run sessions2trash.py
        """
        self.server = server
        self.password = password
        self.db = db or 0
        host, port = (self.server.split(':') + ['6379'])[:2]
        port = int(port)
        self.debug = debug
        if current and current.request:
            self.app = current.request.application
        else:
            self.app = ''
        self.r_server = redis.Redis(host=host, port=port, db=self.db, password=self.password)
        if with_lock:
            RedisClient._release_script = \
                    self.r_server.register_script(_LUA_RELEASE_LOCK)
        self.tablename = None
        self.session_expiry = session_expiry
        self.with_lock = with_lock
cache.py 文件源码 项目:Indushell 作者: SecarmaLabs 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
cache.py 文件源码 项目:Liljimbo-Chatbot 作者: chrisjim316 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
util.py 文件源码 项目:BlogSpider 作者: hack4code 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def get_stats(url, spids):
    stats = {}
    conf = parse_redis_url(url)
    r = redis.Redis(host=conf.host,
                    port=conf.port,
                    db=conf.database)
    for spid in spids:
        n = None
        try:
            n = r.get(spid)
            r.delete(spid)
        except redis.exceptions.ConnectionError:
            logger.error('Error in get_stats failed to connect redis server')
        n = 0 if n is None else int(n)
        stats[spid] = n
    return stats
cache.py 文件源码 项目:flask_system 作者: prashasy 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self, host='localhost', port=6379, password=None,
                 db=0, default_timeout=300, key_prefix=None, **kwargs):
        BaseCache.__init__(self, default_timeout)
        if isinstance(host, string_types):
            try:
                import redis
            except ImportError:
                raise RuntimeError('no redis module found')
            if kwargs.get('decode_responses', None):
                raise ValueError('decode_responses is not supported by '
                                 'RedisCache.')
            self._client = redis.Redis(host=host, port=port, password=password,
                                       db=db, **kwargs)
        else:
            self._client = host
        self.key_prefix = key_prefix or ''
worker.py 文件源码 项目:rca-evaluation 作者: sieve-microservices 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def worker():
    with Connection(Redis("jobqueue.local")):
        qs = sys.argv[1:] or ['default']
        print("foo")
        w = Worker(qs)
        w.work()
gimel.py 文件源码 项目:gimel 作者: Alephbet 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _redis():
    redis_config = config['redis']
    return redis.Redis(**redis_config)


问题


面经


文章

微信
公众号

扫码关注公众号