-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory-database.js
55 lines (46 loc) · 993 Bytes
/
memory-database.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
52
53
54
55
class MemoryDatabase {
constructor({ redisClient }) {
this.memory = redisClient;
}
async keys(pattern) {
return new Promise((resolve, reject) => {
this.memory.keys(pattern, (err, keys) => {
if (err) {
reject(err);
}
resolve(keys);
});
});
}
async set(key, value) {
return new Promise((resolve, reject) => {
this.memory.set(key, JSON.stringify(value), err => {
if (err) {
reject(err);
}
resolve();
});
});
}
async get(key) {
return new Promise((resolve, reject) => {
this.memory.get(key, (err, value) => {
if (err) {
reject(err);
}
resolve(JSON.parse(value));
});
});
}
async del(key) {
return new Promise((resolve, reject) => {
this.memory.del(key, err => {
if (err) {
reject(err);
}
resolve();
});
});
}
}
module.exports = { MemoryDatabase };