Socket
Book a DemoInstallSign in
Socket

rexsync

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rexsync

rexSync allows you to handle expired keys efficiently, whether it's for syncing data, triggering workflows, or maintaining logs

1.0.73
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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

# install locally
npm i --save rexsync

Usage

// ES6 import
import { RexSync } from "rexsync";

const rex = new RexSync({
    redisUrl: "<redis-url>",
    
    // Enable or disable logging of expired keys.
    // Set to `true` to log which key expired, or `false` to disable logging.
    logExpireKey: true, // or false
    
    // Define the transport method for handling expiration events.
    transport: {
        // Option 1: Use a custom function to handle expiration events.
        method: "function",
        onExpiration: async (key) => {
            // Handle the expired key as needed.
            // For example, refresh your Redis cache or synchronize it with your database:
            await refreshCache(key);
        }
    },
    
    // Option 2: Use a webhook to handle expiration events.
    transport: {
        method: "webhook",
        url: "https://yourapp.com/webhooks",
        auth: {
            type: 'apikey', // Valid types: 'bearerToken', 'basic', 'apikey', or 'no-auth'.
            name: 'x-api-key',
            value: '<your-api-key>'
        }
    },
    
    // Option 3: Use RabbitMQ to handle expiration events.
    transport: {
        method: "rabbitmq",
        exchange: "<rabbitmq-exchange>",
        type: "<rabbitmq-exchange-type>",
        queue: "<rabbitmq-queue>",
        routing: "<rabbitmq-routing-key>",
        url: "<rabbitmq-url>"
    }
});

// Start listening for key expiration events.
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

  • bearerToken
transport: {
    method: "webhook",
    auth: {
        type: "bearerToken",
        token: "<authorization token>"
    }
}
  • basic
transport: {
    method: "webhook",
    auth: {
        type: "basic",
        username: "<username>",
        password: "<password>"
    }
}

Keywords

redis

FAQs

Package last updated on 03 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.