chore(release): 1.2.0 [skip ci] # [1.2.0](https://github.com/node-casbin/redis-watcher/compare/v1.1.0...v1.2.0) (2026-02-02) ### Features * fix bug that NPM released, but github not released ([#37](https://github.com/node-casbin/redis-watcher/issues/37)) ([a5f78ed](https://github.com/node-casbin/redis-watcher/commit/a5f78ede3f552c37351f1cf495f8ea49d86c5e0f)) * fix CI build by pinning @types/babel__traverse for TypeScript 3.7.4 compatibility ([#39](https://github.com/node-casbin/redis-watcher/issues/39)) ([16afbd5](https://github.com/node-casbin/redis-watcher/commit/16afbd545544d1f53351caaa53a299910e21c34e))
Redis Watcher is the Redis watcher for Node-Casbin. With this library, Node-Casbin can synchronize policy changes across multiple enforcer instances via Redis pub/sub.
This watcher is based on ioredis and supports both single Redis instances and Redis clusters.
npm install @casbin/redis-watcher
Note: The old package name redis-watcher has been deprecated on NPM. Please use @casbin/redis-watcher instead.
Using 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 }
Using Redis Cluster:
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 }
This project is under Apache 2.0 License. See the LICENSE file for the full license text.