rexSync
rexSync is a lightweight NodeJS module designed to listen to Redis key expiration events in real-time. By leveraging Redis keyspace notifications, rexSync allows you to handle expired keys efficiently, whether it's for syncing data, triggering workflows, or maintaining logs. This module simplifies the process of capturing and responding to key expiration events, making it an essential tool for managing Redis cache objects.
Key Features
- Real-Time Expiration Listening: Automatically listens to Redis key expiration events using keyspace notifications.
- Lightweight and Fast: Optimized for high-performance Redis environments with minimal overhead.
- Easy Integration: Simple to set up and integrate with existing Node.js applications.
- Flexible Use Cases: Ideal for data syncing, logging, workflow automation, and more.
- Configurable Storage Options: Sync expired keys to databases or external systems (optional).
Installation
npm i --save rexsync
Usage
import { RexSync } from "rexsync";
const rex = new RexSync({
redisUrl: "<redis-url>",
logExpireKey: true,
transport: {
method: "function",
onExpiration: async (key) => {
await refreshCache(key);
}
},
transport: {
method: "webhook",
url: "https://yourapp.com/webhooks",
auth: {
type: 'apikey',
name: 'x-api-key',
value: '<your-api-key>'
}
},
transport: {
method: "rabbitmq",
exchange: "<rabbitmq-exchange>",
type: "<rabbitmq-exchange-type>",
queue: "<rabbitmq-queue>",
routing: "<rabbitmq-routing-key>",
url: "<rabbitmq-url>"
}
});
rex.startListening();
[!NOTE]
The type
in RabbitMQ transport defines the exchange type used for routing messages. Supported types are: direct
, fanout
, headers
, topic
, and x-consistent-hash
. If no type is specified, the default exchange type is topic
.
Webhook Auth
transport: {
method: "webhook",
auth: {
type: "bearerToken",
token: "<authorization token>"
}
}
transport: {
method: "webhook",
auth: {
type: "basic",
username: "<username>",
password: "<password>"
}
}