Python werkzeug.contrib.cache 模块,RedisCache() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用werkzeug.contrib.cache.RedisCache()

项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def redis(app, config, args, kwargs):
        kwargs.update(dict(
            host=config.get('CACHE_REDIS_HOST', 'localhost'),
            port=config.get('CACHE_REDIS_PORT', 6379),
        ))
        password = config.get('CACHE_REDIS_PASSWORD')
        if password:
            kwargs['password'] = password

        key_prefix = config.get('CACHE_KEY_PREFIX')
        if key_prefix:
            kwargs['key_prefix'] = key_prefix

        db_number = config.get('CACHE_REDIS_DB')
        if db_number:
            kwargs['db'] = db_number

        redis_url = config.get('CACHE_REDIS_URL')
        if redis_url:
            kwargs['host'] = redis_from_url(
                                redis_url,
                                db=kwargs.pop('db', None),
                            )

        return RedisCache(*args, **kwargs)
项目:FileStoreGAE    作者:liantian-cn    | 项目源码 | 文件源码
def redis(app, config, args, kwargs):
        kwargs.update(dict(
            host=config.get('CACHE_REDIS_HOST', 'localhost'),
            port=config.get('CACHE_REDIS_PORT', 6379),
        ))
        password = config.get('CACHE_REDIS_PASSWORD')
        if password:
            kwargs['password'] = password

        key_prefix = config.get('CACHE_KEY_PREFIX')
        if key_prefix:
            kwargs['key_prefix'] = key_prefix

        db_number = config.get('CACHE_REDIS_DB')
        if db_number:
            kwargs['db'] = db_number

        redis_url = config.get('CACHE_REDIS_URL')
        if redis_url:
            kwargs['host'] = redis_from_url(
                                redis_url,
                                db=kwargs.pop('db', None),
                            )

        return RedisCache(*args, **kwargs)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def make_cache(self):
        return cache.RedisCache(key_prefix='werkzeug-test-case:')
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def filesystem(app, config, args, kwargs):
    args.insert(0, config['CACHE_DIR'])
    kwargs.update(dict(threshold=config['CACHE_THRESHOLD']))
    return FileSystemCache(*args, **kwargs)

# RedisCache is supported since Werkzeug 0.7.
项目:FileStoreGAE    作者:liantian-cn    | 项目源码 | 文件源码
def filesystem(app, config, args, kwargs):
    args.insert(0, config['CACHE_DIR'])
    kwargs.update(dict(threshold=config['CACHE_THRESHOLD']))
    return FileSystemCache(*args, **kwargs)

# RedisCache is supported since Werkzeug 0.7.
项目:edmunds    作者:LowieHuyghe    | 项目源码 | 文件源码
def test_redis(self):
        """
        Test the redis
        """

        # Write config
        self.write_config([
            "from edmunds.cache.drivers.redis import Redis \n",
            "APP = { \n",
            "   'cache': { \n",
            "       'enabled': True, \n",
            "       'instances': [ \n",
            "           { \n",
            "               'name': 'redis',\n",
            "               'driver': Redis,\n",
            "               'host': 'localhost',\n",
            "               'port': 6379,\n",
            "               'password': None,\n",
            "               'db': 0,\n",
            "               'default_timeout': 300,\n",
            "               'key_prefix': None,\n",
            "           }, \n",
            "       ], \n",
            "   }, \n",
            "} \n",
            ])

        # Create app
        app = self.create_application()

        driver = app.cache()
        self.assert_is_instance(driver, Redis)
        self.assert_is_instance(driver, RedisCache)
项目:website    作者:DiscordEmotes    | 项目源码 | 文件源码
def get_redis():
    if not hasattr(current_app, 'redis'):
        host, port = current_app.config["REDIS_CONN"]
        cache = RedisCache(host, port, default_timeout=300)

        current_app.redis = cache

    return current_app.redis