redis-sequelize-ts
v1.1.14
Published
A TypeScript and nodeJs utility library for seamless integration of Redis caching with Sequelize, enhancing performance and scalability in your Sequelize-based applications.
Downloads
33
Readme
redis-sequelize-ts
A TypeScript and nodeJs utility library for seamless integration of Redis caching with Sequelize, enhancing performance and scalability in your Sequelize-based applications.
Installation
npm install redis-sequelize-ts
Usage
1. Setup server connection in your project
const redis = require('redis');
const url = 'redis://'+ 'localhost' +':'+ '6379';
const client = redis.createClient(url)
.on('error', err => console.log('Redis Client Error', err))
.connect();
const cacheQuery = require('redis-sequelize-ts').default;
const { User, sequelize } = require('../models/index');
let data = await cacheQuery.findAll(User.sequelize, client, "User", {}, 259200)
import * as redis from 'redis';
const url = 'redis://'+ 'localhost' +':'+ '6379';
const client = redis.createClient(url)
.on('error', err => console.log('Redis Client Error', err))
.connect();
import cacheQuery from 'redis-sequelize-ts';
import User from '../models/User'
let data = await cacheQuery.findAll(User.sequelize,client,"User",{},259200)
2. Create Sequelize Models
Use the getModels
function to retrieve predefined Sequelize models for users, user_meta, and user_roles. The user_roles model is automatically populated with data for the 'user' and 'admin' roles. Additionally, you can dynamically add fields to the user model using createModel()
.
import { Sequelize } from 'sequelize';
import * as myLib from 'jnext-library-ts';
const sequelize = new Sequelize('dbName', 'root', '', {
dialect: 'mysql',
host: '127.0.0.1',
logging: false
});
myLib.getModels();
myLib.createModel('customUserModel', sequelize, {
// Define additional fields here
filedName: dataType // Datatype should be string. Ex. 'STRING' , 'INTEGER'
});
Acknowledgements