Redis caching in CRUD with Sequelize (MySQL)
Based on this sample, you can refer to appropriate caching when using Sequelize in CRUD work.
- Clone this git
$ git clone https://github.com/zinirun/sequelize-redis-caching.git- Define your database(MySQL) at
.env
DATABASE = "YOUR_DATABASE_NAME"
DB_USER = "YOUR_DATABASE_USER"
DB_PASSWORD = "YOUR_DATABASE_PASSWORD"
DB_HOST = "localhost"- Start express
$ yarn install # npm install
$ yarn start # npm startYou can define your Redis host
redisHostat./admin/admin.ctrl.js(It assumes Redis Client runs as Host Docker by default)
Controllers are defined at ./admin/admin.ctrl.js. Cached data is saved as JSON.stringify and loaded as JSON.parse.
-
Set Cache from Redis (when C, U, D)
post_products_writepost_products_editpost_products_delete
-
Get Cache from Redis (when R)
get_products- It uses Promisify function
getAsync - It accesses Sequelize when redis has no cache
- It uses Promisify function