Skip to content

Instantly share code, notes, and snippets.

@medisoft
Created October 23, 2019 23:43
Show Gist options
  • Save medisoft/7ae230f36592d3d8358957342c1a08b2 to your computer and use it in GitHub Desktop.
Save medisoft/7ae230f36592d3d8358957342c1a08b2 to your computer and use it in GitHub Desktop.
const keyHash = (params) => {
let hash = '';
_.each(params, (val, key) => {
hash+=`${key}:${val}`;
});
return hash;
}
const execQueryCached = async (params) => {
const hash = keyHash(params);
if(await redis.existAsync(hash)) return await redis.getAsync(hash);
const result = await execQuery(params);
return await redis.setAsync(hash, result).then(()=>result);
}
@medisoft
Copy link
Author

this one is to add a "query cache" in redis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment