Get unlimited public & private packages + team-based management with npm Teams.Learn more »

distribucache-redis-store

6.0.2 • Public • Published

Distribucache Redis Store Build Status NPM version

A Redis datastore for the Distribucache auto-repopulating cache.

Usage

Here's what a simple service using Distribucache with Redis may look like:

import distribucache from 'distribucache';
import redisStore from 'distribucache-redis-store';
import model from '../model'; // for example
 
const store = redisStore({host: 'localhost', port: 6379});
const cacheClient = distribucache.createClient(store);
 
const cache = cacheClient.create('my:values', {
  staleIn: '10 sec',
  populateIn: '5 sec',
  pausePopulateIn: '1 min',
  populate(key, cb) {
    model.get(key, cb);
  }
});
 
class Service {
  get(key, cb) {
    cache.get(key, cb);
  }
}

API

  • redisStore(config)

Possible config values below.

{String} [config.namespace]
{Boolean} [config.isPreconfigured] defaults to false (see note below)
{Object} [config.options] see ioredis options

isPreconfigured is used to determine whether the store needs to set-up keyspace notifications, which are used to support the populateIn feature in a way that multiple Distribucache clients would not conflict with each other while automatically populating the cache. Disable this to avoid a warning if you're running Redis in an environment where CONFIG is not available. One such environment is AWS. There you will need to set the notify-keyspace-events property to Kx manually through the AWS Management Console.

In addition to the config above, all of the options defined in ioredis are allowed to configure the Redis client.

License

MIT

Install

npm i distribucache-redis-store

DownloadsWeekly Downloads

4

Version

6.0.2

License

none

Last publish

Collaborators

  • avatar
  • avatar