Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cache-manager-redis-store

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-manager-redis-store

Redis store for node-cache-manager

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
188K
decreased by-2.93%
Maintainers
1
Weekly downloads
 
Created

What is cache-manager-redis-store?

The cache-manager-redis-store npm package is a Redis store for the cache-manager module. It allows you to use Redis as a caching backend for your Node.js applications, providing a simple and efficient way to cache data and improve performance.

What are cache-manager-redis-store's main functionalities?

Basic Setup

This code demonstrates how to set up a basic cache using cache-manager-redis-store. It initializes a cache with Redis as the backend, specifying the host, port, and time-to-live (TTL) for cached items.

const cacheManager = require('cache-manager');
const redisStore = require('cache-manager-redis-store');

const cache = cacheManager.caching({
  store: redisStore,
  host: 'localhost', // default value
  port: 6379, // default value
  ttl: 600 // time to live in seconds
});

Set and Get Cache

This code demonstrates how to set a value in the cache and then retrieve it. The value 'bar' is stored with the key 'foo' and a TTL of 10 seconds. The value is then retrieved and logged to the console.

cache.set('foo', 'bar', { ttl: 10 }, (err) => {
  if (err) throw err;

  cache.get('foo', (err, result) => {
    if (err) throw err;
    console.log(result); // 'bar'
  });
});

Wrap Function

This code demonstrates how to use the wrap function to cache the result of a long-running operation. The wrap function checks if the value is already in the cache; if not, it executes the provided function, caches the result, and returns it.

cache.wrap('foo', (cb) => {
  // Simulate a long-running operation
  setTimeout(() => {
    cb(null, 'bar');
  }, 2000);
}, { ttl: 10 }, (err, result) => {
  if (err) throw err;
  console.log(result); // 'bar'
});

Del Cache

This code demonstrates how to delete a value from the cache. The value associated with the key 'foo' is removed from the cache.

cache.del('foo', (err) => {
  if (err) throw err;
  console.log('Cache for key foo deleted');
});

Other packages similar to cache-manager-redis-store

FAQs

Package last updated on 16 Oct 2022

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc