當前位置: 首頁>>代碼示例>>Python>>正文


Python Redis.from_url方法代碼示例

本文整理匯總了Python中redis.Redis.from_url方法的典型用法代碼示例。如果您正苦於以下問題:Python Redis.from_url方法的具體用法?Python Redis.from_url怎麽用?Python Redis.from_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.Redis的用法示例。


在下文中一共展示了Redis.from_url方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_app

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def create_app():

    # setting the static_url_path to blank serves static files from the web root
    app = Flask(__name__, static_url_path='')
    app.config.from_object(__name__)

    Swagger(app, template_file='definitions.yaml')

    app.redis = Redis.from_url(app.config['REDIS_URL'])
    app.task_queue = rq.Queue('recon-tasks', connection=app.redis)

    @app.after_request
    def disable_cache(response):
        response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
        return response

    @app.route('/')
    def index():
        return render_template('index.html', workspaces=recon._get_workspaces())

    from recon.core.web.api import resources
    app.register_blueprint(resources)

    return app 
開發者ID:lanmaster53,項目名稱:recon-ng,代碼行數:26,代碼來源:__init__.py

示例2: test_isdisjoint

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def test_isdisjoint(self):
        a = RedisSet('abc')
        b = RedisSet('cde')
        assert not a.isdisjoint(b)
        c = RedisSet('def')
        assert a.isdisjoint(c)

        other_url = 'redis://127.0.0.1:6379/'
        other_redis = Redis.from_url(other_url, socket_timeout=1)
        b = RedisSet('cde', redis=other_redis)
        assert not a.isdisjoint(b)
        c = RedisSet('def', redis=other_redis)
        assert a.isdisjoint(c)

        d = {'c', 'd', 'e'}
        assert not a.isdisjoint(d)
        e = {'d', 'e', 'f'}
        assert a.isdisjoint(e) 
開發者ID:brainix,項目名稱:pottery,代碼行數:20,代碼來源:test_set.py

示例3: __init__

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def __init__(self, *args, **kwargs):
        """
        args and kwargs are forwarded to redis.from_url
        """
        self.redis = Redis.from_url(*args, decode_responses=True, **kwargs) 
開發者ID:steinitzu,項目名稱:celery-singleton,代碼行數:7,代碼來源:redis.py

示例4: __init__

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def __init__(self, config):
        """
        Use redis as the streaming client.

        Configuration keys:
            REDIS_URL
            REDIS_CHANNEL
            REDIS_SLEEP_TIME

        """
        self.channel = config['REDIS_CHANNEL']
        self.sleep_time = config.get('REDIS_SLEEP_TIME', 0.1)
        self.redis = Redis.from_url(config['REDIS_URL'])
        self.receiver_thread: Optional[PubSubWorkerThread] = None 
開發者ID:microsoft,項目名稱:agogosml,代碼行數:16,代碼來源:redis_streaming_client.py

示例5: __init__

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def __init__(self):
        self.redis = Redis.from_url(settings.REDIS_URL) 
開發者ID:gnosis,項目名稱:safe-relay-service,代碼行數:4,代碼來源:redis_repository.py

示例6: get_database

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def get_database(config, master=True):
    if config['sentinel']:
        sentinal = Sentinel(config['sentinel'], socket_timeout=0.1,
                            password=config['redis_password'], db=config['redis_database'])
        if master:
            return sentinal.master_for(config['sentinel_cluster_name'])
        else:
            return sentinal.slave_for(config['sentinel_cluster_name'])
    else:
        return Redis.from_url(config['redis']) 
開發者ID:openprocurement,項目名稱:openprocurement.auction,代碼行數:12,代碼來源:utils.py

示例7: __init__

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def __init__(self):
        self.redis = Redis.from_url(self.URL) 
開發者ID:alephdata,項目名稱:followthemoney,代碼行數:4,代碼來源:cache.py

示例8: init_db

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def init_db(self, url=None):
        self.redis = Redis.from_url(url or self.redis_url) 
開發者ID:qmppz,項目名稱:igotolibrary,代碼行數:4,代碼來源:RedisHelper.py

示例9: __init__

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def __init__(self):
        # redis 操作客戶端
        self._client = pyRedis.from_url(PERSISTENCE['url'])
        # 可搜索項
        self._index_keys = ('anonymity', 'protocol') 
開發者ID:gavin66,項目名稱:proxy_list,代碼行數:7,代碼來源:redis_impl.py

示例10: main

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def main():
    # Bootstrap the worker assets
    bugbug_http.boot.boot_worker()

    # Provide queue names to listen to as arguments to this script,
    # similar to rq worker
    redis_url = os.environ.get("REDIS_URL", "redis://localhost/0")
    redis_conn = Redis.from_url(redis_url)
    with Connection(connection=redis_conn):
        qs = sys.argv[1:] or ["default"]

        w = Worker(qs)
        w.work() 
開發者ID:mozilla,項目名稱:bugbug,代碼行數:15,代碼來源:worker.py

示例11: cache_redis_connection_url

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def cache_redis_connection_url(self, value: Optional[str]) -> None:
        self._cache_redis_connection_url = value
        if value is not None:
            self._cache_redis = Redis.from_url(value) 
開發者ID:rominf,項目名稱:profanity-filter,代碼行數:6,代碼來源:profanity_filter.py

示例12: restart

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def restart(access_key):
    """Restarts a failed job"""

    account_id = Account.authorize(request.values.get('api_key'))

    jobs = Job.query.filter_by(access_key = access_key)
    job = jobs.first()
    
    if job == None or not account_id or not account_id == job.account_id:
        return jsonify(api_error('API_UNAUTHORIZED')), 401

    if not job.failed:
        return jsonify(api_error('JOBS_NOT_RESTARTABLE')), 400

    if job.data_deleted:
        return jsonify(api_error('JOBS_DATA_DELETED')), 400

    ip = fix_ip(request.headers.get('x-forwarded-for', request.remote_addr))

    job.ip_address = ip
    job.failed = 0
    job.fail_code = 0
    job.status = 'queued'
    db.session.commit()
    redis_conn = Redis.from_url(os.environ.get('REDIS_URI'))
    q = Queue(job.account.get_priority(), connection=redis_conn)
    q.enqueue_call(func=send_fax, args=(job.id,), timeout=3600)

    return jsonify(job.public_data()) 
開發者ID:lyonbros,項目名稱:faxrobot,代碼行數:31,代碼來源:jobs.py

示例13: charge

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def charge():
    if request.values.get("admin_token") != os.environ.get("ADMIN_TOKEN"):
        return jsonify(api_error("ADMIN_BAD_ADMIN_TOKEN")), 401

    redis_conn = Redis.from_url(current_app.config['REDIS_URI'])
    q = Queue('default', connection=redis_conn)
    q.enqueue_call(func=charge_subscribers,  timeout=300)

    return jsonify({"kthx": "bai"}) 
開發者ID:lyonbros,項目名稱:faxrobot,代碼行數:11,代碼來源:accounts.py

示例14: __init__

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def __init__(self):
        """Create a new Redis instance when a new object for this class is created.
        """
        self.redis = Redis.from_url(CACHE_URL)
        logger.info('Connected to Redis at ' + CACHE_URL) 
開發者ID:Jonarzz,項目名稱:DotaResponsesRedditBot,代碼行數:7,代碼來源:redis_cache.py

示例15: __init__

# 需要導入模塊: from redis import Redis [as 別名]
# 或者: from redis.Redis import from_url [as 別名]
def __init__(self, queue=None, redis_url=None, queue_name='kaneda'):
        if not Redis:
            raise ImproperlyConfigured('You need to install redis to use the RQ queue.')
        if not Queue:
            raise ImproperlyConfigured('You need to install rq library to use the RQ queue.')
        if queue:
            if not isinstance(queue, Queue):
                raise ImproperlyConfigured('"queue" parameter is not an instance of RQ queue.')
            self.queue = queue
        elif redis_url:
            self.queue = Queue(queue_name, connection=Redis.from_url(redis_url))
        else:
            self.queue = Queue(queue_name, connection=Redis()) 
開發者ID:APSL,項目名稱:kaneda,代碼行數:15,代碼來源:rq.py


注:本文中的redis.Redis.from_url方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。