Skip to content

Commit

Permalink
explore caching w/ redis
Browse files Browse the repository at this point in the history
  • Loading branch information
przemwierzbicki committed Nov 29, 2019
1 parent 5790de0 commit 6e00812
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions routes/blogRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ module.exports = app => {
});

app.get('/api/blogs', requireLogin, async (req, res) => {
const redis = require('redis');
const util = require('util');
const redisUrl = 'redis://127.0.0.1:6379';
const client = redis.createClient(redisUrl);
client.get = util.promisify(client.get);

const cachedBlogs = await client.get(req.user.id);

const blogs = await Blog.find({ _user: req.user.id });

res.send(blogs);
Expand Down

0 comments on commit 6e00812

Please sign in to comment.