npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tirke/node-cache-manager-ioredis

v3.6.0

Published

[![npm version](https://badge.fury.io/js/@tirke%2Fnode-cache-manager-ioredis.svg)](https://badge.fury.io/js/@tirke%2Fnode-cache-manager-ioredis)

Downloads

22,154

Readme

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

All examples have changed a bit since the new major version of node-cache-manager Everything is now based on promises everywhere, no more callbacks.

TTL

TTL value is forwarded directly to ioredis which uses seconds as unit.

Init

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

import { ioRedisStore } from '@tirke/node-cache-manager-ioredis'
import { caching } from 'cache-manager'

// Default
const defaultRedisCache = caching(ioRedisStore, {
  host: 'localhost', // default value
  port: 6379, // default value
  password: 'XXXXX',
  ttl: 60,
})

// With instanceConfig accepting type RedisOptions
const instanceRedisCache = caching(ioRedisStore, {
  instanceConfig: {
    host: 'localhost', // default value
    port: 6379, // default value
    password: 'XXXXX',
  },
  ttl: 60,
})

// With clusterConfig accepting type ClusterConfig
const clusterRedisCache = caching(ioRedisStore, {
  clusterConfig: {
    nodes: [
      { port: 6380, host: '127.0.0.1' },
      { port: 6381, host: '127.0.0.1' },
    ],
  },
  ttl: 60,
})

// Finally passing a instiantiated IORedis instance type Redis | Cluster
import Redis from 'ioredis'
const instance = new Redis()
const instantiatedRedisCache = caching(ioRedisStore, {
  redisInstance: instance,
  ttl: 60,
})

Generic usage

import { ioRedisStore, RedisCache } from '@tirke/node-cache-manager-ioredis'
import { caching } from 'cache-manager'

const redisCache: RedisCache = caching(ioRedisStore, {
  host: 'localhost', // default value
  port: 6379, // default value
  password: 'XXXXX',
  ttl: 600,
})

// listen for redis connection error event
const cache = redisCache.store
cache.client.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')

Flush all DBs

import { ioRedisStore, RedisCache } from '@tirke/node-cache-manager-ioredis'
import { caching } from 'cache-manager'

const redisCache: RedisCache = caching(ioRedisStore, {
  host: 'localhost', // default value
  port: 6379, // default value
  password: 'XXXXX',
  ttl: 600,
})

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

// it uses `flushall` under the hood, so it drops all DBs
await redisCache.reset()