本文整理汇总了Python中flask_redis.FlaskRedis方法的典型用法代码示例。如果您正苦于以下问题:Python flask_redis.FlaskRedis方法的具体用法?Python flask_redis.FlaskRedis怎么用?Python flask_redis.FlaskRedis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_redis
的用法示例。
在下文中一共展示了flask_redis.FlaskRedis方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import flask_redis [as 别名]
# 或者: from flask_redis import FlaskRedis [as 别名]
def __init__(self, app, user_id=0):
self.redis_client = FlaskRedis(app)
self.key = 'ctfd_whale_lock-' + str(user_id)
self.lock = None
self.global_port_key = "ctfd_whale-port-set"
self.global_network_key = "ctfd_whale-network-set"
示例2: check_redis_connected
# 需要导入模块: import flask_redis [as 别名]
# 或者: from flask_redis import FlaskRedis [as 别名]
def check_redis_connected(client):
"""
A built-in check to connect to Redis using the given client and see
if it responds to the ``PING`` command.
It's automatically added to the list of Dockerflow checks if a
:class:`~redis.StrictRedis` instances is passed
to the :class:`~dockerflow.flask.app.Dockerflow` class during
instantiation, e.g.::
import redis
from flask import Flask
from dockerflow.flask import Dockerflow
app = Flask(__name__)
redis_client = redis.StrictRedis(host='localhost', port=6379, db=0)
dockerflow = Dockerflow(app, redis=redis)
An alternative approach to instantiating a Redis client directly
would be using the `Flask-Redis <https://github.com/underyx/flask-redis>`_
Flask extension::
from flask import Flask
from flask_redis import FlaskRedis
from dockerflow.flask import Dockerflow
app = Flask(__name__)
app.config['REDIS_URL'] = 'redis://:password@localhost:6379/0'
redis_store = FlaskRedis(app)
dockerflow = Dockerflow(app, redis=redis_store)
"""
import redis
errors = []
try:
result = client.ping()
except redis.ConnectionError as e:
msg = "Could not connect to redis: {!s}".format(e)
errors.append(Error(msg, id=health.ERROR_CANNOT_CONNECT_REDIS))
except redis.RedisError as e:
errors.append(
Error('Redis error: "{!s}"'.format(e), id=health.ERROR_REDIS_EXCEPTION)
)
else:
if not result:
errors.append(Error("Redis ping failed", id=health.ERROR_REDIS_PING_FAILED))
return errors