Coder Social home page Coder Social logo

sequelize-redis's Introduction

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

  1. 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);
  1. 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:

Key Description Default value
ttl Defines cache TTL (seconds) null
  1. 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:

  1. Sequelize response (same as on original method)
  2. 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)

sequelize-redis's People

Contributors

hazelmeow avatar idangozlan avatar rmoura-92 avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sequelize-redis's Issues

Error: "Cannot find module 'babel-runtime/helpers/extends'"

When I require this package, I get an error when I start the server. Am I doing something wrong?

const SequelizeRedis = require('sequelize-redis')
Error: Cannot find module 'babel-runtime/helpers/extends'
    at Function.Module._resolveFilename (module.js:543:15)
    at Function.Module._load (module.js:470:25)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/br/Sites/eurolink/api_gateway/node_modules/sequelize-redis/lib/index.js:7:17)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)

I've already tried deleting the node_modules folder and doing npm install.

The cache dosent save included associations

Hi im using this whit
const [user, cacheHit] = await this.User.findByIdCached('1_p', 1, { include: ['role'] });
and when is not cached it return the included role, but when the data cames from the cache it dosent. Any suggestion how to proceed? Or its simply not supported.

Update Redis Dependency

npm audit is reporting that sequelize-redis is using an outdated version of redis that is vulnerable to a DDoS attack. I can submit a PR if it would help you guys otherwise will you guys be updating soon?

┌──────────────────────────────────────────────────────────────────────────────┐ │ Manual Review │ │ Some vulnerabilities require your attention to resolve │ │ │ │ Visit https://go.npm.me/audit-guide for additional guidance │ └──────────────────────────────────────────────────────────────────────────────┘ ┌───────────────┬──────────────────────────────────────────────────────────────┐ │ Low │ Regular Expression Denial of Service │ ├───────────────┼──────────────────────────────────────────────────────────────┤ │ Package │ redis │ ├───────────────┼──────────────────────────────────────────────────────────────┤ │ Patched in │ >=3.1.1 │ ├───────────────┼──────────────────────────────────────────────────────────────┤ │ Dependency of │ sequelize-redis │ ├───────────────┼──────────────────────────────────────────────────────────────┤ │ Path │ sequelize-redis > redis │ ├───────────────┼──────────────────────────────────────────────────────────────┤ │ More info │ https://npmjs.com/advisories/1662 │ └───────────────┴──────────────────────────────────────────────────────────────┘

Timestamps missing

I noticed that the timestamps are missing on the instance when there is a cache hit. The fields are defined on the model, even when specifying the exact attributes they are still missing

node_redis: Deprecated: The GET command contains a "undefined" argument.

error:

node_redis: Deprecated: The GET command contains a "undefined" argument.
This is converted to a "undefined" string now and will return an error from v.3.0 on.
Please handle this in your code to make sure everything works as you intended it to.

npm dependencies
"redis": "^2.8.0",
"sequelize": "^5.0.0-beta.9",
"sequelize-redis": "^1.0.6",
"bluebird": "^3.5.1",

redis sql : 3.2

node_redis: Deprecated: The GET command contains a argument of type Object.

Hello,

I got this warning :

This is converted to "[object Object]" by using .toString() now and will return an error from v.3.0 on.
Please handle this in your code to make sure everything works as you intended it to.

With this npm dependencies :
"redis": "2.8.0",
"sequelize": "^4.38.0",
"sequelize-redis": "1.0.6",
"bluebird": "3.5.1",

The repo is still maintain ?
Have a nice day !

Unable to read .env file for node js app in Heroku local

Hi,

I'm working on a App built on Nodejs in heroku system. When im trying to run this app locally looks like the .env file is created is not read when imsending a request through PostMan. Any idea why im seeing this error:

(node:9152) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Running on PORT: 8080
Redis client connected
line 21 InfusionFeedRoute.handleInfusionFeedPost JSON req.body: {"request_id":"5d55e4ec-ad6e-4734-a1bf-16ce90b7af57","business_unit":"infusion","source_system":"CPR_Plus","data_source":"CPR_Plus","process":"patient_notes_feed","drug":{"external_id":"","ndc":"null","gpi":"null","name":"null","cpr_drug":"null"},"prescriber":{"external_id":"","npi":"null","last_name":"null","first_name":"null","address":"null","city":"null","state":"null","zip":"null","phone_main":"null","phone_fax":"null","dea":"null","specialty_physician_therapy":"null","email":"null","cprplus_doc_number":"null"},"patient":{"status":"New Patient5","mrn":"455789332","last_name":"Test date23","first_name":"patient feed7","gender":"Female","dob":"1990-03-07","cag":"Test Cag124","insurance_member_id":"09876543225","address":"11111 Joy Street","city":"Austin","state":"TX","zip":"78748","country":"US","phone_main":"111-111-1114","physician":"12345","phone_fax":"222-222-2222","therapy_category":"Autoimmunity","icd_code":"D50-D89","icd_code_description":"Diseases of the blood and blood-forming organs and certain disorder involving the immune mechanism testttt","referral_date":"10/2/2018 23:43:51","language":"English","sales_rep_name":"Test Sales Rep Name","npi":"123456789"},"referral":{"referral_rn":"null","mrn":"23457","referral_status":"Active","referral_source":"null","npi":"null","ordered_on_datetime":"null","ordered_modified_on_datetime":"null","prescription_number":"null","primary_insurance_plan_name":"null","rank":"null"},"workflow_task":{"task_id":"","referral_rn":"null","mrn":"null","npi":"null","latest_task_name":"null","latest_task_outcome":"null","change_date":"null","sales_rep_name":"null","nursing_coordinator":"null","task_status":"null","site":"null","outcome_reason":"null","outcome_comment":"null"},"patient_notes":{"external_id":"null","mrn":"34567","notes_type":"workflow task","notes_subject":"null","notes_body":"null ","source_created_by":"null","source_created_dt":"null","source_modified_by":"null","source_modified_dt":"null"}}
node_redis: Deprecated: The GET command contains a "undefined" argument.
This is converted to a "undefined" string now and will return an error from v.3.0 on.
Please handle this in your code to make sure everything works as you intended it to.
node_redis: Deprecated: The GET command contains a "undefined" argument.
This is converted to a "undefined" string now and will return an error from v.3.0 on.
Please handle this in your code to make sure everything works as you intended it to.
Error: INVALID_LOGIN: Invalid username, password, security token; or user locked out.

Let me know if i need to provide more details.
Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.