Redis Watcher for Casbin-RS
Redis Watcher is a Redis watcher for Casbin-RS. It's designed to be compatible with the Go version of casbin-redis-watcher.
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= "2.2"
= { = "1.0", = ["full"] }
Simple Example
use *;
use ;
use Arc;
use Mutex;
async
Redis Cluster Example
For Redis Cluster deployment:
use *;
use ;
Running Tests
Standalone Redis Tests
# Start Redis
# Run tests
Redis Cluster Tests
# Setup Redis Cluster (see CI configuration for detailed setup)
# Or use the setup script provided
# Run cluster tests
API
WatcherOptions
Configure the Redis watcher:
let options = default
.with_channel // Redis pub/sub channel
.with_ignore_self // Ignore messages from this instance
.with_local_id; // Custom instance ID (auto-generated if not set)
RedisWatcher
Create watchers for standalone Redis or Redis cluster:
// Standalone Redis
let watcher = new?;
// Redis Cluster (comma-separated node URLs)
let cluster_urls = "redis://127.0.0.1:7000,redis://127.0.0.1:7001,redis://127.0.0.1:7002";
let watcher = new_cluster?;
Update Callbacks
Set a custom callback to handle policy updates:
watcher.set_update_callback;
Features
- ✅ Compatible with casbin-redis-watcher (Go version)
- ✅ Support for standalone Redis and Redis Cluster
- ✅ Synchronous design for easy integration
- ✅ Automatic policy change notifications via Redis pub/sub
- ✅ Custom update callbacks
- ✅ Message filtering (ignore self-generated messages)
- ✅ Comprehensive error handling with thiserror
- ✅ Thread-safe design with proper cleanup
Requirements
- Rust 1.82+
- Redis 5.0+ (for standalone mode)
- Redis Cluster 5.0+ (for cluster mode)
CI/CD
This project includes comprehensive CI/CD pipelines:
- Unit tests: Run on all platforms (Linux, macOS, Windows)
- Integration tests:
- Standalone Redis tests on Linux with Redis service
- Redis Cluster tests on Linux with 6-node cluster setup
- Cross-platform support: Tested on multiple Rust versions (1.82+, stable)
Getting Help
License
This project is under Apache 2.0 License. See the LICENSE file for the full license text.