pycasbin的Redis watcher适配器
pycasbin-redis-watcher的Python项目详细描述
pycasbin redis观察器
用于监视Casbin策略更新的Casbin角色监视程序
安装
pip install pycasbin-redis-watcher
基本用法
与https://github.com/ScienceLogic/pycasbin/flask-authz一起使用的示例
^{pr2}$与UWSGI一起使用
这个redis watcher模块启动订阅redis通道的独立进程,并监听该通道上casbin策略的更新。在WSGI上下文(如uwsgi)中运行时,您可能希望将这些进程作为postfork操作启动。如下所示:
try:
from uwsgidecorators import postfork
print("Running in uwsgi context")
except ModuleNotFoundError:
print("Not running in uwsgi context")
postfork = None
if postfork:
@postfork
def load_watcher():
global casbin_enforcer
watcher = RedisWatcher(redis_info.hostname, redis_info.port)
watcher.set_update_callback(casbin_enforcer.e.load_policy)
casbin_enforcer.set_watcher(watcher)
- 项目
标签: