本文整理汇总了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
示例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)
示例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)
示例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
示例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)
示例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'])
示例7: __init__
# 需要导入模块: from redis import Redis [as 别名]
# 或者: from redis.Redis import from_url [as 别名]
def __init__(self):
self.redis = Redis.from_url(self.URL)
示例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)
示例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')
示例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()
示例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)
示例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())
示例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"})
示例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)
示例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())