Registry / database / node-caching-mysql-connector-with-redis

node-caching-mysql-connector-with-redis

JSON →
library2.8.0jsnpmunverified

Node.js library that integrates MySQL with Redis caching for automatic query caching, auto key generation, auto cache invalidation, and transparent fallback during Redis outages. Version 2.8.0. Uses mysql2 connection pool with automatic reconnection, redis ioredis with exponential backoff, and supports transactions, pagination, bulk inserts, and query timeouts. Differentiators: zero-config setup via environment variables, production-grade resilience tested against 18 chaos scenarios (Redis/MySQL kills, network partitions, thundering herd), cluster-safe cache invalidation using SCAN, and TypeScript type definitions included. The library degrades gracefully: reads return empty arrays and writes proceed without caching when Redis is down; no unhandled errors or crashes. Suitable for e-commerce, multi-tenant SaaS, real-time apps, and bulk operations.

npm install node-caching-mysql-connector-with-redis
INSTALL
IMPORT
SIG · NODE-CACHING-MYSQL
N
node-caching-mysql-connector-with-redis
databasejavascriptv2.8.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getCacheQuery
const { getCacheQuery } = require('node-caching-mysql-connector-with-redis')
import { getCacheQuery } from 'node-caching-mysql-connector-with-redis'
Library is CommonJS; use require(), not ESM imports. TypeScript users should use import syntax with allowSyntheticDefaultImports.
QuaryCache
const { QuaryCache } = require('node-caching-mysql-connector-with-redis')
const { queryCache } = require('...')
Function name is QuaryCache (typo intentional — it's the exported name). Capital Q and missing 'e' after 'r'.
withTransaction
const { withTransaction } = require('node-caching-mysql-connector-with-redis')
const { transaction } = require('...')
Exported function is named withTransaction, not transaction or createTransaction.
isRedisConnected
const { isRedisConnected } = require('node-caching-mysql-connector-with-redis')
Utility function to check Redis connection status, returns boolean.
getCacheQueryPagination
const { getCacheQueryPagination } = require('node-caching-mysql-connector-with-redis')
For paginated cached queries.

Shows basic usage: cached read, write with auto invalidation, transaction, health check, and graceful shutdown. Requires .env variables set.

const { getCacheQuery, QuaryCache, withTransaction, isRedisConnected } = require('node-caching-mysql-connector-with-redis'); // async context async function main() { // Read with auto-caching const user = await getCacheQuery('SELECT * FROM users WHERE id = ?', [1]); console.log(user); // Write with auto cache invalidation await QuaryCache('INSERT INTO users (name) VALUES (?)', ['Alice']); // Transaction with automatic commit/rollback await withTransaction(async (tx) => { const result = await tx.query('INSERT INTO orders (user_id, total) VALUES (?, ?)', [1, 99.99]); await tx.query('UPDATE users SET orders_count = orders_count + 1 WHERE id = ?', [1]); }); // Health check const connected = isRedisConnected(); console.log('Redis connected:', connected); // Graceful shutdown const { closeConnections } = require('node-caching-mysql-connector-with-redis'); await closeConnections(); } main().catch(console.error);
Debug
Known issues
gotchaFunction name 'QuaryCache' has a typo (missing 'e' after 'r') — this is the actual exported name.
fix
Use exactly 'QuaryCache' when destructuring; do not expect 'queryCache' or 'QueryCache'.
affects: >=1.0.0
gotchaLibrary is CommonJS only. ESM imports will fail with SyntaxError.
fix
Use require() instead of import. If using TypeScript, set "esModuleInterop": true and use import syntax that compiles to require().
affects: >=1.0.0
breakingBefore v2.0, the package used a different API with 'query' and 'cache' separate. The current API unified under getCacheQuery and QuaryCache.
fix
Upgrade to v2.8.0 and refactor to use getCacheQuery for reads and QuaryCache for writes.
affects: <2.0
gotchaEnvironment variables must be set before requiring the package. The library reads .env on first import; missing variables will cause connection failures silently.
fix
Use dotenv.config() early in your application entry point and ensure required vars are present: DB_HOST, DB_USERNAME, DB_NAME, REDIS_SERVER.
affects: >=1.0.0
deprecatedThe option CORE_AUTO_FEATURES is deprecated in favor of individual feature flags (not documented). It currently defaults to true.
fix
Set CORE_AUTO_FEATURES=true in .env; future versions may remove this variable entirely.
affects: >=2.5.0
Errors
Common errors & fixes
Cannot find module 'mysql2'
Missing required peer dependency mysql2.
fix
Run: npm install mysql2
Cannot find module 'ioredis'
Missing required peer dependency ioredis.
fix
Run: npm install ioredis
const { QuaryCache } = require('node-caching-mysql-connector-with-redis'); TypeError: (0 , _driver.QuaryCache) is not a function
Possible import style mismatch; using ESM import instead of require.
fix
Use const { QuaryCache } = require('node-caching-mysql-connector-with-redis') — not import syntax.
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or inaccessible.
fix
Start Redis server: redis-server, or set REDIS_SERVER and REDIS_PORT in .env.
Error: getaddrinfo ENOTFOUND localhost
Database host 'localhost' is not resolved, or MySQL not running.
fix
Ensure MySQL is running and DB_HOST is correct. Use 127.0.0.1 instead of localhost if DNS issues.
Upgrade
Version history
2.8.0latest on npm
Audit
Dependencies
mysql2requiredMySQL connection pool with auto-reconnection and prepared statements
ioredisrequiredRedis client with reconnection and cluster support
Agent activity
4 hits · last 30 days
node
4
Resources
node-caching-mysql-connector-with-redis — npm install node-caching-mysql-connector-with-redis · libregistry