New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

redis-toolkits-js

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

redis-toolkits-js

Lightweight Redis utility functions for caching and pub/sub

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

redis-toolkits-js

A simple and lightweight Redis utility toolkit for Node.js — provides built-in helpers for caching and pub/sub patterns using the official redis client.

📦 Installation

npm install redis-toolkits-js

Ensure Redis is running locally or provide a connection URL via the environment:

REDIS_URL=redis://localhost:6379

🚀 Quick Start

import {
  getOrSetCache,
  clearCache,
  publish,
  subscribe,
  redisClient
} from 'redis-toolkits-js';

// Cache example
const data = await getOrSetCache('my-key', async () => {
  const res = await fetch('https://jsonplaceholder.typicode.com/users');
  return res.json();
}, 300);

// Pub/Sub example
publish('notifications', { type: 'user_signup', userId: 1 });

subscribe('notifications', (msg) => {
  console.log('Received:', msg);
});

🧩 API Reference

🔹 getOrSetCache(key, callbackFn, expireInSeconds = 3600)

  • Returns cached value if available.
  • If not, executes callbackFn, caches the result, and returns it.
const value = await getOrSetCache('users', async () => fetchUsers(), 300);

🔹 clearCache(key)

  • Deletes a specific key from Redis cache.
await clearCache('users');

🔹 publish(channel, message)

  • Publishes a JSON-serializable message to a Redis channel.
await publish('log-channel', { level: 'info', message: 'User signed in' });

🔹 subscribe(channel, callback)

  • Subscribes to a Redis channel and executes the callback for every message.
await subscribe('log-channel', (msg) => {
  console.log('New log message:', msg);
});

⚙️ Configuration

You can configure the Redis client using the REDIS_URL environment variable or modify the connection settings in src/connection.js.

Default:

REDIS_URL=redis://localhost:6379

📁 Project Structure

redis-toolkits-js
/
├── src/
│   ├── cache.js       # Caching utilities
│   ├── pubsub.js      # Pub/Sub handlers
│   ├── connection.js  # Redis client connection
│   └── index.js       # Main exports
├── README.md
├── package.json

🛠 Requirements

  • Node.js v16+
  • Redis server (local or remote)
  • redis npm package (v4+)

🧪 Coming Soon

  • Retry strategies
  • Namespaced cache support
  • TTL-aware cache invalidation
  • Unit tests & TypeScript typings

📝 License

MIT © 2025
Created and maintained by Nurul Islam Rimon

Keywords

redis

FAQs

Package last updated on 23 May 2025

Related posts