本文整理汇总了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)
示例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
示例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 = []
示例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)
示例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)
示例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)
示例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
示例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
示例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'])
示例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']))
示例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()
示例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
示例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()
示例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
示例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()