-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.js
More file actions
36 lines (31 loc) · 747 Bytes
/
cache.js
File metadata and controls
36 lines (31 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const redis = require("async-redis");
const client = redis.createClient();
const expirationTime = 60 * 60;
async function setCache(username, data) {
try {
let key = `username=${username}`;
return await client.set(key, expirationTime, data);
} catch(e) {
return e.toString();
}
}
async function getCache(username) {
try {
let key = `username=${username}`;
let data = await client.get(key);
return JSON.parse(data);
} catch(e) {
return e.toString();
}
}
async function clearCache(username) {
try {
let key = `username=${username}`;
return await client.del(key);
} catch(e) {
return e.toString();
}
}
module.exports.setCache = setCache;
module.exports.getCache = getCache;
module.exports.clearCache = clearCache;