@actvalue/mrc
v0.0.0-beta-4
Published
wrapper for MySQL queries with Redis caching
Downloads
7
Readme
@actvalue/mysql-redis-cache
Wrapper for MySQL queries with Redis caching.
Install
yarn add @actvalue/mysql-redis-cache
npm i @actvalue/mysql-redis-cache
Client Usage
The client is used to execute queries and caching the result.
import { MRCClient } from '@actvalue/mysql-redis-cache';
const mysqlConfig = {
host: '<mysql host>',
port: 3306,
user: '<user>',
password: '<password>',
database: '<db>',
connectionLimit: 5,
};
const redisConfig = {
username: '<user>',
password: '<password>',
socket: {
host: '<redis host>',
port: 6379,
connectionTimeout: 30000,
},
};
// create instance and connect
const mrc = new MRCClient(mysqlConfig, redisConfig);
// execute queries
const query = 'SELECT * FROM table WHERE name = ?';
const params = ['Alberto'];
const paramNames = ['Name'];
const ttl = 3600; // default is 24h
const result = await mrc.queryWithCache(query, params, paramNames, ttl);
Server Usage
The server is used to delete cached queries.
import { MRCServer } from '@actvalue/mysql-redis-cache';
const redisConfig = {
username: '<user>',
password: '<password>',
socket: {
host: '<redis host>',
port: 6379,
connectionTimeout: 30000,
},
};
// create instance and connect
const mrc = new MRCServer(redisConfig);
// delete all queries concerning StoreId = 6
await mrc.dropOutdatedCache(['StoreId'], [6]);