@junaid1460/simple-redis-cache
v1.0.13
Published
Cache function return value in redis
Downloads
1
Readme
Simple redis cache
Cache data easily with a simple wrap.
npm i @junaid1460/simple-redis-cache
Usage
typescript:
import { RedisCache } from "@junaid1460/simple-redis-cache";
const cache = new RedisCache({
host: "localhost",
});
function myFunc(x: number, y: number) {
return cache.cached({
expiresAfter: 10, // seconds
keys: [x, y], // list of number or string to construct key
// closure
func: async () => {
return x * y;
},
});
}
myFunc(1, 2).get().then((e) => console.log(e.hit, e.data));
Javascript:
const redisCache = require('@junaid1460/simple-redis-cache')
const cache = new redisCache.RedisCache({
host: 'localhost'
})
function myFunc(x, y) {
return cache.cached({
expiresAfter: 10, // seconds
keys: [x, y], // list of number or string to construct key
// closure
func: async () => {
return x * y;
},
});
}
myFunc(1, 2).delete().then((e) => console.log());