Finish
10 files changed
tree: d6c7858918d0a4d20238e261f231b199d3f9556e
  1. examples/
  2. src/
  3. test/
  4. .gitignore
  5. .prettierrc
  6. .travis.yml
  7. jest.config.js
  8. LICENSE
  9. package.json
  10. README.md
  11. tsconfig.json
  12. tslint.json
  13. yarn.lock
README.md

redis-watcher

Redis watcher for node-casbin

Installation

# NPM
npm install --save redis-watcher

# Yarn
yarn add redis-watcher

Simple Example

import { RedisWatcher } from './lib/watcher';
import { newEnforcer } from 'casbin';

// Initialize the watcher.
const watcher = await RedisWatcher.newWatcher('redis://localhost:6379/5');

// Initialize the enforcer.
const enforcer = await newEnforcer('examples/authz_model.conf', 'examples/authz_policy.csv');

enforcer.setWatcher(watcher);

// By default, the watcher's callback is automatically set to the
// enforcer's loadPolicy() in the setWatcher() call.
// We can change it by explicitly setting a callback.
watcher.setUpdateCallback(() => console.log('Casbin need update'));