New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sequelize-redis

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sequelize-redis

A semi-automatic caching wrapper for Sequelize NodeJS framework

latest
Source
npmnpm
Version
1.0.12
Version published
Weekly downloads
25
92.31%
Maintainers
1
Weekly downloads
 
Created
Source

sequelize-redis

Build Status codecov.io Code Coverage Known Vulnerabilities

A semi-automatic caching wrapper for Sequelize v4 NodeJS framework

Installation


npm install sequelize-redis

requirements

Usage

  • Init our Sequelize cache manager:
import SequelizeRedis from 'sequelize-redis';
import redis from 'redis';
import bluebird from 'bluebird';

// Let's promisify Redis
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);

// Define your redisClient
const redisClient = redis.createClient({ /* Redis configuration comes here */ });

// Let's start
const sequelizeRedis = new SequelizeRedis(redisClient);
  • Wrap our the Sequelize original model:
// models.User refers to model of sequelize
const User = sequelizeRedis.getModel(models.User, { ttl: 60 * 60 * 24 });

The second argument of getModel is optional:

KeyDescriptionDefault value
ttlDefines cache TTL (seconds)null
  • Then we can start use the model wrapper:
const userUUID = '75292c75-4c7a-4a11-92ac-57f929f50e23';
const userCacheKey = `user_${userUUID}`;
// We can use the default sequelize methods by adding suffix of "Cached" 
// for example, findbyPkCached: 
const [user, cacheHit] = await User.findbyPkCached(userCacheKey, userUUID);
// We can also use the non cached methods (original methods)
const user = await User.findbyPk(userUUID);

Results of Cached methods (for ex. findbyPkCached) will be array with following arguments:

  • Sequelize response (same as on original method)
  • Cache hit indication (true / false)

Supported Methods: find findOne findAll findAndCount findAndCountAll findbyPk all min max sum count

Cache Invalidation

Just use regular Redis API:

redisClient.del('SampleKey');

Contribution

Feel free to contribute and submit issues.

PR

Please make sure that your code is linted and getting build successfully

Thanks

Inspired by rfink/sequelize-redis-cache/

License

MIT (Idan Gozlan)

FAQs

Package last updated on 31 Jan 2019

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