本文整理匯總了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()