Redis 监视器
雷迪斯监视器是 重写 监视器 节点卡斯宾。有了这个库,Node-Casbin就可以通过Redis pub/sub在多个执行人实例中同步政策变化.
这个监视器基于 雄风 并同时支持单个 Redis 实例和 Redis 集群.
安装
npm install @casbin/redis-watcher
注:旧软件包名称 redis-watcher 国家防范机制已经贬值。 请使用 @casbin/redis-watcher 换句话说.
简单示例
使用 Redis :
import { RedisWatcher } from '@casbin/redis-watcher';
import { newEnforcer } from 'casbin';
async function myFunction() {
// Initialize the watcher
// See https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
const watcher = await RedisWatcher.newWatcher('redis://localhost:6379/5');
// Initialize the enforcer
const enforcer = await newEnforcer('examples/authz_model.conf', 'examples/authz_policy.csv');
// Set the watcher for the enforcer
enforcer.setWatcher(watcher);
// Update the policy
await enforcer.addPolicy('alice', 'data1', 'read');
// The policy change will be synchronized to other enforcers via Redis pub/sub
}
使用 Redis 组 :
import { RedisWatcher } from '@casbin/redis-watcher';
import { newEnforcer } from 'casbin';
async function myFunction() {
// Initialize the watcher with Redis cluster
// See https://github.com/luin/ioredis/blob/master/API.md#new-clusterstartupnodes-options
const watcher = await RedisWatcher.newWatcherWithCluster([
{ port: 7000, host: 'localhost' },
{ port: 7001, host: 'localhost' },
{ port: 7002, host: 'localhost' }
]);
// Initialize the enforcer
const enforcer = await newEnforcer('examples/authz_model.conf', 'examples/authz_policy.csv');
// Set the watcher for the enforcer
enforcer.setWatcher(watcher);
// Update the policy
await enforcer.addPolicy('bob', 'data2', 'write');
// The policy change will be synchronized to other enforcers via Redis pub/sub
}
获取帮助
许可证
这个项目是在Apache 2.0许可下进行的. 见 自由主义 完整许可证文本的文件.