hodei-authz-sdk-authz-redis
Redis cache invalidation adapter for the Hodei authorization framework.
Overview
hodei-authz-sdk-authz-redis provides a Redis-based implementation of the CacheInvalidation trait from hodei-authz-sdk-authz. It enables distributed cache invalidation using Redis Pub/Sub, perfect for multi-instance deployments.
Features
- CacheInvalidation Implementation: Pub/Sub for policy updates
- Distributed: Works across multiple application instances
- Async/Await: Built on tokio and redis-rs
- Connection Testing: Validates Redis connection on startup
- Error Handling: Typed errors with detailed messages
Installation
[]
= "0.1"
= { = "0.32", = ["tokio-comp"] }
Usage
Basic Setup
use RedisCacheInvalidation;
use CacheInvalidation;
async
Publishing Invalidation Events
use CacheInvalidation;
// After updating a policy, invalidate caches
cache.invalidate_policies.await?;
Subscribing to Invalidation Events
use CacheInvalidation;
use Arc;
let cache = new;
let cache_clone = cache.clone;
// Spawn subscriber in background
spawn;
Complete Example with Policy Store
use PostgresPolicyStore;
use RedisCacheInvalidation;
use ;
use Arc;
use RwLock;
async
Redis Pub/Sub Channel
The adapter uses the channel: hodei-authz-sdk:policy:invalidate
Error Handling
use CacheError;
match cache.invalidate_policies.await
Testing
Integration tests require a running Redis instance:
# Start Redis
# Run tests
REDIS_URL="redis://localhost:6379"
License
MIT OR Apache-2.0