A caching layer between MySQL (mysql/mysql2) and Redis (redis/ioredis) that transparently caches SELECT query results in Redis to reduce database load. Stable version 0.7.2, last updated in 2018. It hashes queries using configurable algorithms (md5, farmhash32/64, blake2b512, or full query) and stores results in Redis with TTL. Zero mandatory external dependencies (farmhash is optional). Designed for read-heavy workloads with static or rarely updated data. Falls back to MySQL if Redis is unavailable. Not suitable for frequently updated data due to potential cache staleness.
npm install mysql-redisNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows synchronous callback usage of MysqlRedis with mysql2 and redis. Cache options are optional.
Install farmhash as a separate dependency: npm install farmhash. Or switch to md5 hash type.
Ensure you only use MySQLRedis.query() for SELECT statements. For writes, use the native MySQL connection directly.
Manually delete or update the Redis keys when data changes, or use a TTL and accept eventual consistency.
Use md5 (default) or blake2b512 for collision-safe hashing, especially with millions of queries.
Use require() or use a dynamic import with module.createRequire.
Install farmhash: npm install farmhash, or change hashType to 'md5'.
Use const { MysqlRedis } = require('mysql-redis');Ensure Redis is running on localhost:6379 or provide correct connection options to redis.createClient.