redis-caching
v1.0.0
Published
A driver for caching mongodb with redis
Downloads
2
Readme
redis caching with mongodb
setup
To configure redis and MongoDB do
const rm = require('redis-caching');
rm({
// host: '/tmp/redis.sock', //unix domain
// host: '127.0.0.1', //can be IP or hostname
port: 6379,
maxRetries: 10, //reconnect retries, default -1 (infinity)
auth: '', //optional password, if needed
db: 0, //optional db selection
autoConnect: true, //will connect after creation
doNotSetClientName: false, //will set connection name (you can see connections by running CLIENT LIST on redis server)
doNotRunQuitOnEnd: false, //when you call `end()`, driver tries to send `QUIT` command to redis before actual end
});
Redis handling
isCached
To check if an key is cached in redis you write the following
rm.isCached(key, callback);
cache
To cache data you run the following function
rm.cache(
key,
document,
settings,
callback
);
Settigns could be the following
{
forceUpdate: true,
duration: -1
}
forceUpdate set to true overwrites the data if already cached duration is how long the key should be active, -1 is infinite
uncache
To uncache data the following function is called
rm.unCache(
key,
settings,
callback
);
Settings could be the following
{
forceDel: true,
duration: 10
}
forceDel deletes the key without taking duration into account duration sets a duration for when it should delete