add TTL to redis set in wrapper

merge-requests/208/head
fatchan 5 years ago
parent b0db29f7c7
commit 8e5d1a15f8
  1. 4
      db/boards.js
  2. 8
      redis.js

@ -15,12 +15,12 @@ module.exports = {
} else {
board = await db.findOne({ '_id': name });
if (board) {
cache.set(`board_${name}`, board);
cache.set(`board_${name}`, board, 3600);
if (board.banners.length > 0) {
cache.sadd(`banners_${name}`, board.banners);
}
} else {
cache.set(`board_${name}`, 'no_exist', 'ex', 3600); //1 hour expiry just so it doesnt grow indefinitely
cache.set(`board_${name}`, 'no_exist', 600);
}
}
return board;

@ -14,8 +14,12 @@ module.exports = {
},
//set a value on key
set: (key, value) => {
return client.set(key, JSON.stringify(value));
set: (key, value, ttl) => {
if (ttl) {
client.set(key, JSON.stringify(value), 'EX', ttl);
} else {
client.set(key, JSON.stringify(value));
}
},
//add items to a set

Loading…
Cancel
Save