0.0.0-beta-4 • Published 1 year ago

@actvalue/mrc v0.0.0-beta-4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@actvalue/mysql-redis-cache

npm version npm tot downloads npm license

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]);
0.0.0-beta-4

1 year ago

0.0.0-beta-3

1 year ago

0.0.0-beta-2

1 year ago

0.0.0-beta-1

1 year ago