-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.server.radis.js
49 lines (39 loc) · 964 Bytes
/
db.server.radis.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
var redis = require("redis");
var client = redis.createClient({
url: "",
});
client.on("connect", function () {
console.log("Redis Database connected" + "\n");
});
client.on("reconnecting", function () {
console.log("Redis client reconnecting");
});
client.on("ready", function () {
console.log("Redis client is ready");
});
client.on("error", function (err) {
console.log("Something went wrong " + err);
});
client.on("end", function () {
console.log("\nRedis client disconnected");
console.log("Server is going down now...");
process.exit();
});
module.exports.set = (key, value) => {
client.set(key, value, redis.print);
return "done";
};
module.exports.get = (key) => {
return new Promise((resolve, reject) => {
client.get(key, function (error, result) {
if (error) {
console.log(error);
reject(error);
}
resolve(result);
});
});
};
module.exports.close = () => {
client.quit();
};