当前位置: 首页>>代码示例>>Python>>正文


Python redis.from_url方法代码示例

本文整理汇总了Python中redis.from_url方法的典型用法代码示例。如果您正苦于以下问题:Python redis.from_url方法的具体用法?Python redis.from_url怎么用?Python redis.from_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在redis的用法示例。


在下文中一共展示了redis.from_url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_status

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def get_status(task_id):
    with Connection(redis.from_url(current_app.config["REDIS_URL"])):
        q = Queue()
        task = q.fetch_job(task_id)
    if task:
        response_object = {
            "status": "success",
            "data": {
                "task_id": task.get_id(),
                "task_status": task.get_status(),
                "task_result": task.result,
            },
        }
    else:
        response_object = {"status": "error"}
    return jsonify(response_object) 
开发者ID:mjhea0,项目名称:flask-redis-queue,代码行数:18,代码来源:views.py

示例2: _GetRedisClient

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def _GetRedisClient(self):
    """Creates a Redis client for testing.

    This method will attempt to use a Redis server listening on localhost and
    fallback to a fake Redis client if no server is availble or the connection
    timed out.

    Returns:
      Redis: a Redis client.
    """
    try:
      redis_client = redis.from_url(self._REDIS_URL, socket_timeout=60)
      redis_client.ping()
    except redis.exceptions.ConnectionError:
      redis_client = fakeredis.FakeStrictRedis()

    return redis_client 
开发者ID:log2timeline,项目名称:plaso,代码行数:19,代码来源:merge_reader.py

示例3: __init__

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def __init__(self, *args, **kwargs):
        self.broker_url = config.BROKER_URL or DEFAULT_BROKER_URL
        self.redis_url = config.REDIS_URL or DEFAULT_BROKER_URL

        self.log = logging.getLogger('worker').info

        self.redis = redis.from_url(self.redis_url,
                                    decode_responses=True)
        self.log('Connected to redis database')

        discord_config = ClientConfig()
        discord_config.token = config.MEE6_TOKEN
        discord_client = Client(discord_config)
        self.api = discord_client.api

        self.listeners = []
        self.plugins = [] 
开发者ID:cookkkie,项目名称:mee6,代码行数:19,代码来源:worker_bot.py

示例4: reload_config

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def reload_config():
    """
    Triggers a global reloading of the configuration files and reinitializes
    the redis connection pool.

    As of now configuration files are only read from sys.prefix/etc/nidaba/.
    """
    global nidaba_cfg, celery_cfg, Redis
    ipath = path.join(sys.prefix, 'etc', 'nidaba', 'nidaba.yaml')
    with open(ipath, 'rb') as fp:
        nidaba_cfg = yaml.safe_load(fp)
    if 'redis_url' not in nidaba_cfg:
        raise NidabaConfigException('No redis URL defined')
    Redis = redis.from_url(nidaba_cfg['redis_url'])

    cpath = path.join(sys.prefix, 'etc', 'nidaba', 'celery.yaml')
    with open(cpath, 'rb') as fp:
        celery_cfg = yaml.safe_load(fp) 
开发者ID:OpenPhilology,项目名称:nidaba,代码行数:20,代码来源:config.py

示例5: redis

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
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) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:27,代码来源:backends.py

示例6: __init__

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def __init__(self, reports_dir=None):
        # Open redis connection
        self.redis = redis.from_url(taskcluster.secrets["REDIS_URL"])
        assert self.redis.ping(), "Redis server does not ping back"

        # Open gcp connection to bucket
        assert (
            taskcluster.secrets["GOOGLE_CLOUD_STORAGE"] is not None
        ), "Missing GOOGLE_CLOUD_STORAGE secret"
        self.bucket = get_bucket(taskcluster.secrets["GOOGLE_CLOUD_STORAGE"])

        # Local storage for reports
        self.reports_dir = reports_dir or os.path.join(
            tempfile.gettempdir(), "ccov-reports"
        )
        os.makedirs(self.reports_dir, exist_ok=True)
        logger.info("Reports will be stored in {}".format(self.reports_dir))

        # Load most recent reports in cache
        for repo in REPOSITORIES:
            for report in self.list_reports(repo, nb=1):
                self.download_report(report) 
开发者ID:mozilla,项目名称:code-coverage,代码行数:24,代码来源:gcp.py

示例7: grade_project

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def grade_project(project_id):
    project = Project.query.filter_by(id=project_id).first_or_404()
    with Connection(redis.from_url(current_app.config['REDIS_URL'])):
        q = Queue()
        task = q.enqueue(
            create_task,
            project.url,
            current_app.config["OPENFAAS_URL"]
        )
    response_object = {
        'status': 'success',
        'data': {
            'task_id': task.get_id()
        }
    }
    return jsonify(response_object), 202 
开发者ID:testdrivenio,项目名称:openci,代码行数:18,代码来源:views.py

示例8: gettoken

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def gettoken(uid):
    red = redis.from_url(redis_url)
    token = red.get(uid+"-access_token")
    refresh = red.get(uid+"-refresh_token")
    if token:
        return token
    elif refresh:
        #good refresh token
        try:
            payload = {"client_id" : Client_ID, "client_secret" : Client_Secret, "refresh_token" : refresh, "grant_type" : "refresh_token", }
            url = "https://api.amazon.com/auth/o2/token"
            r = requests.post(url, data = payload)
            resp = json.loads(r.text)
            red.set(uid+"-access_token", resp['access_token'])
            red.expire(uid+"-access_token", 3600)
            return resp['access_token']
        #bad refresh token
        except:
            return False
    else:
        return False

# Get Alexa's [text] response to a [text] query 
开发者ID:jacobajit,项目名称:AlexaBot,代码行数:25,代码来源:app.py

示例9: get

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def get(self):
        code=self.get_argument("code")
        mid=self.get_cookie("user")
        path = "https" + "://" + self.request.host 
        callback = path+"/code"
        payload = {"client_id" : Client_ID, "client_secret" : Client_Secret, "code" : code, "grant_type" : "authorization_code", "redirect_uri" : callback }
        url = "https://api.amazon.com/auth/o2/token"
        r = requests.post(url, data = payload)
        red = redis.from_url(redis_url)
        resp = json.loads(r.text)
        if mid != None:
            print("fetched MID: ",mid)
            red.set(mid+"-access_token", resp['access_token'])
            red.expire(mid+"-access_token", 3600)
            red.set(mid+"-refresh_token", resp['refresh_token'])
            self.render("static/return.html")
            bot.send_text_message(mid, "Great, you're logged in. Start talking to Alexa!")
        else:
            self.redirect("/?refreshtoken="+resp['refresh_token']) 
开发者ID:jacobajit,项目名称:AlexaBot,代码行数:21,代码来源:app.py

示例10: push_rq_connection

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def push_rq_connection():
    push_connection(redis.from_url(current_app.config['REDIS_URL'])) 
开发者ID:mjhea0,项目名称:flask-spark-docker,代码行数:4,代码来源:views.py

示例11: run_worker

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def run_worker():
    redis_url = app.config['REDIS_URL']
    redis_connection = redis.from_url(redis_url)
    with Connection(redis_connection):
        worker = Worker(app.config['QUEUES'])
        worker.work() 
开发者ID:mjhea0,项目名称:flask-spark-docker,代码行数:8,代码来源:manage.py

示例12: run_task

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def run_task():
    task_type = request.form["type"]
    with Connection(redis.from_url(current_app.config["REDIS_URL"])):
        q = Queue()
        task = q.enqueue(create_task, task_type)
    response_object = {
        "status": "success",
        "data": {
            "task_id": task.get_id()
        }
    }
    return jsonify(response_object), 202 
开发者ID:mjhea0,项目名称:flask-redis-queue,代码行数:14,代码来源:views.py

示例13: run_worker

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def run_worker():
    redis_url = app.config["REDIS_URL"]
    redis_connection = redis.from_url(redis_url)
    with Connection(redis_connection):
        worker = Worker(app.config["QUEUES"])
        worker.work() 
开发者ID:mjhea0,项目名称:flask-redis-queue,代码行数:8,代码来源:manage.py

示例14: get_redis_connection

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def get_redis_connection():
    redis_connection = getattr(g, '_redis_connection', None)
    if redis_connection is None:
        redis_url = current_app.config['REDIS_URL']
        redis_connection = g._redis_connection = redis.from_url(redis_url)
    return redis_connection 
开发者ID:beenje,项目名称:flask-rq-example,代码行数:8,代码来源:views.py

示例15: runworker

# 需要导入模块: import redis [as 别名]
# 或者: from redis import from_url [as 别名]
def runworker():
    redis_url = app.config['REDIS_URL']
    redis_connection = redis.from_url(redis_url)
    with Connection(redis_connection):
        worker = Worker(app.config['QUEUES'])
        worker.work() 
开发者ID:beenje,项目名称:flask-rq-example,代码行数:8,代码来源:manage.py


注:本文中的redis.from_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。