@tonoid/redis
v2.0.1
Published
Redis plugin for @tonoid/helpers
Downloads
26
Maintainers
Readme
@tonoid/redis
Redis plugin for @tonoid/helpers
Init options
url
: (defaults:process.env.REDIS_URL
) Redis urldb
: (defaults:process.env.REDIS_DB || '0'
) Redis database.extendOptions
: (default:{}
) Extend RedisClient optionserrorHandler
: (default:(err) => {}
) Handle redis connect eror
Exported context attributes
.redisCache
: Redis cacheManager instance.getValue(key)
: Get a value from redis cache.setValue(key, value, ttl)
: Set a value in redis cache (ttl in seconds).delValue(key)
: Delete a value in redis cache.expire(key, value)
: Expire a value in redis cache (value in seconds).incr(key)
: Increment a value in redis cache.decr(key)
: Decrement a value in redis cache
Usage example
const { context, init } = require('@tonoid/helpers');
const redis = require('@tonoid/redis');
(async () => {
await init([
redis({
url: 'redis://localhost:6379',
db: 0,
errorHAndler: (err) => console.error(err)
}),
]);
await context.redis.setValue('foo', 'bar', 60); // 1min ttl
const fooValue = await context.redis.getValue('foo');
console.log(fooValue);
})();
Credits
This module is maintained by Simo Elalj @tonoid