
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
hybrid-cache
Advanced tools
The hybrid-cache caches in-memory and synchronizes on Redis servers. It only supports some basic commands and focuses on fastest response.
npm install hybrid-cache
'use strict';
const HybridCache = require('hybrid-cache');
const hybridCache = HybridCache();
hybridCache.init({
waitingTime: 3, // Default 2 seconds
isSyncRedis: true // Default false
});
hybridCache.addRedisServer({
connString: null,
host: '127.0.0.1',
port: '3000',
password: null,
retryTime: 2, // Default retry 5 times
retryInterval: 5 // Waiting 2 seconds between each retry
}, function (err, result) {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.addRedisServer('redis://<user>:<pwd>@<host>:<port>', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
console.log();
hybridCache.set('key1', 'value1', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.setex('key2', 1, 'value2', (err, result) =>{
console.log(`Error: ${err} Result: ${result}`);
});
console.log();
hybridCache.get('key1', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.get('key2', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
setTimeout(() => {
console.log();
hybridCache.get('key1', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.get('key2', (err, result) =>{
console.log(`Error: ${err} Result: ${result}`);
});
}, 2000);
setTimeout(() => {
console.log();
hybridCache.flushall();
hybridCache.get('key1', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.get('key2', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
}, 3000);
setTimeout(() => {
console.log();
hybridCache.incrby('AAA', 10, (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
}, 4000);
setTimeout(() => {
console.log();
hybridCache.Redis.set('keyInRedis', 'valueInRedis', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.Redis.get('keyInRedis', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.Mem.get('keyInRedis', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.get('keyInRedis', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
}, 5000);
setTimeout(() => {
console.log();
hybridCache.Mem.set('keyInMem', 'valueInMem', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.Redis.get('keyInMem', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.get('keyInMem', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.Mem.get('keyInMem', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
}, 6000);
setTimeout(() => {
console.log();
hybridCache.Mem.setex('keyInMem2', 1, 'valueInMem2', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.Redis.get('keyInMem2', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.get('keyInMem2', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.Mem.get('keyInMem2', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
}, 7000);
setTimeout(() => {
console.log();
hybridCache.Redis.get('keyInMem2', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.get('keyInMem2', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
hybridCache.Mem.get('keyInMem2', (err, result) => {
console.log(`Error: ${err} Result: ${result}`);
});
}, 9000);
This will display:
Error: null Result: OK
Error: null Result: OK
Error: null Result: OK
Error: null Result: OK
Error: null Result: value1
Error: null Result: value2
Error: null Result: value1
Error: null Result: null
Error: null Result: null
Error: null Result: null
Error: null Result: 10
Error: null Result: null
Error: null Result: OK
Error: null Result: valueInRedis
Error: null Result: valueInRedis
Error: null Result: OK
Error: null Result: valueInMem
Error: null Result: valueInMem
Error: null Result: null
Error: null Result: OK
Error: null Result: valueInMem2
Error: null Result: valueInMem2
Error: null Result: null
Error: null Result: null
Error: null Result: null
Error: null Result: null
Note that the API is entirely asynchronous. To get data back from the server, you'll need to use a callback.
Set key to hold the string value. If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.
Return value
Simple string reply: always OK.
Set key to hold the string value and set key to timeout after a given number of seconds. An error is returned when seconds is invalid.
Return value
Simple string reply
Get the value of key. If the key does not exist the special value null is returned.
Return value
Bulk string reply: the value of key, or null when key does not exist or timeout (setWaitingTime function).
Increments the number stored at key by increment. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.
Return value
Integer reply: the value of key after the increment
To only use Redis, Redis.* support full list of commands implemented by Redis. For more details, please refer https://redis.io/commands.
Set key to hold the string value. If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.
Return value
Simple string reply: always OK.
Set key to hold the string value and set key to timeout after a given number of seconds. An error is returned when seconds is invalid.
Return value
Simple string reply
Get the value of key. If the key does not exist the special value null is returned.
Return value
Bulk string reply: the value of key, or null when key does not exist.
FAQs
hybrid-cache is a cache uses memory-cache and Redis
We found that hybrid-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.