New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tirke/node-cache-manager-ioredis

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tirke/node-cache-manager-ioredis

[![codecov](https://codecov.io/gh/Tirke/node-cache-manager-ioredis/branch/main/graph/badge.svg?token=8B6YUE99N3)](https://codecov.io/gh/Tirke/node-cache-manager-ioredis) [![npm version](https://badge.fury.io/js/@tirke%2Fnode-cache-manager-ioredis.svg)](ht

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

codecov npm version

IORedis store for node cache manager

Redis cache store for node-cache-manager.

This is a rewrite of dabroek/node-cache-manager-ioredis. It uses TypeScript with updated dependencies and missing features added. It aims to provide the most simple wrapper possible by just passing the configuration to the underlying ioredis package.

Installation

npm install @tirke/node-cache-manager-ioredis
yarn add @tirke/node-cache-manager-ioredis
pnpm add @tirke/node-cache-manager-ioredis

Usage Examples

Init

I wanted to provide more type-safe ways to init the cache-manager.

import { IoRedisStore, Store } from '@tirke/node-cache-manager-ioredis'
import { caching } from 'cache-manager'

// Default
const defaultRedisCache = caching({
  store: IoRedisStore,
  host: 'localhost', // default value
  port: 6379, // default value
  password: 'XXXXX',
  db: 0,
  ttl: 600,
})

// With instanceConfig acceptingt type RedisOptions
const instanceRedisCache = caching({
  store: IoRedisStore,
  instanceConfig: {
    host: 'localhost', // default value
    port: 6379, // default value
    password: 'XXXXX',
  },
  ttl: 600,
})

// With clusterConfig acceptingt type ClusterConfig
const clusterRedisCache = caching({
  store: IoRedisStore,
  clusterConfig: {
    nodes: [
      { port: 6380, host: '127.0.0.1' },
      { port: 6381, host: '127.0.0.1' },
    ],
  },
  ttl: 600,
})

// Finaly passing a instiantiated IORedis instance type Redis | Cluster
import Redis from 'ioredis'
const instance = new Redis()
const instantiatedRedisCache = caching({
  store: IoRedisStore,
  redisInstance: instance,
  ttl: 600,
})

Generic usage with promises

import { IoRedisStore, Store } from '@tirke/node-cache-manager-ioredis'
import { caching } from 'cache-manager'

const redisCache = caching({
  store: IoRedisStore,
  host: 'localhost', // default value
  port: 6379, // default value
  password: 'XXXXX',
  db: 0,
  ttl: 600,
})

// listen for redis connection error event
const cache = redisCache.store as Store
const redisClient = cache.getClient()
redisClient.on('error', (error: unknown) => {
  // handle error here
  console.log(error)
})

await redisCache.set('foo', 'bar', { ttl: 5 })
const result = await redisCache.get('foo')
await redisCache.del('foo')

FAQs

Package last updated on 25 Aug 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