alien-node-redis-utils
Helper functions for Redis cache on NodeJS. The functions are pure and curried with Ramda.
Install
$ npm install alien-node-redis-utils --save
Run the specs
$ npm test
Methods
getItem
Get an item from the Redis store, provided a recognized cacheKey
var redis = redisClient = redis cacheUtils = redisClient; cacheUtils ;
setItem
Set an item in the Redis store. Adds if key does not exist, otherwise updates the cache.
var redis = redisClient = redis cacheUtils = redisClient; var TWO_HOURS_IN_SECONDS_CACHE_EXPIRE = 1000 * 60 * 60 * 2; var cacheKey = 'someKey' data = foo : 'bar' ; cacheUtils; ;
deleteItem
Delete an item from the Redis store, provided a recognized cacheKey
var redis = redisClient = redis cacheUtils = redisClient; cacheUtils ;
Helpers
maybeAddToQueryCache
Checks for an existing record matching cacheKey
and appends/prepends item
var User = data = name : 'joe'; var redis = redisClient = redis cacheUtils = redisClient; var CACHE_KEY = 'api.users' CACHE_EXPIRE = 1000 * 60 * 60 * 24; return User;
pluckFromQueryCache
Checks for an existing record matching cacheKey
, looks for an item matching a
provided identifierProperty
, removes the item and resets the cache.
var User = data = id : 123; var redis = redisClient = redis cacheUtils = redisClient; var CACHE_KEY = 'api.users'; return User
setOrDeleteCacheBucket
Checks for an existing record matching cacheKey
, and sets it to items
if items
is a populated list. If items
is falsy or an empty array, cacheKey
will be deleted.
// See internal usage from pluckFromQueryCache method: var pluckFromQueryCache = R;