-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.js
51 lines (47 loc) · 1.29 KB
/
cache.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const redis = require('redis');
/**
* Sets a value for the cache
* @param {redis_client}
* @param {string} key to set to value
* @param {string} value to set key to
*/
module.exports.set_value = async function(client, key, value) {
return new Promise(function (resolve, reject) {
client.set(key, value, function(err, reply){
if(err) {
reject ("Failed to SET value in cache, "+ err)
} else {
client.quit();
resolve(reply)
}
});
});
}
/**
* Gets a value from the cache
* @param {redis_client}
* @param {string} value to retrieve
*/
module.exports.get_value = async function(client, key) {
return new Promise(function (resolve, reject) {
// console.log("in promise")
client.get(key, function(err, reply){
if(err) {
reject ("Failed to GET from cache, "+ err)
} else {
client.quit();
resolve(reply);
}
});
});
}
/**
* Creates the connection to the data store
*/
module.exports.client_setup = function(config){ // to be set via process.env later
const redisOptions = {
host: config.host,
port: config.port
}
return redis.createClient(redisOptions);
}