-
Notifications
You must be signed in to change notification settings - Fork 0
/
seatsRedis.js
61 lines (52 loc) · 1.09 KB
/
seatsRedis.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
56
57
58
59
60
61
/* Implementation of different function to access the redis DB */
const client = require('./app').client
//check if busID exists
async function exists(id) {
try{
var x= await client.exists("seats_"+id);
return x;
} catch(err) {
console.log(err);
}
}
//insert seats of bus
async function set(id, seats) {
try{
await client.rpush('seats_'+id, ...seats);
} catch(err) {
console.log(err)
}
}
//get seats of bus
async function get(id) {
try{
result = await client.lrange('seats_'+id, 0, -1);
return result;
} catch(err) {
console.log(err)
}
}
//update the seat status
async function update(id, seatno, val) {
try{
result = await client.lset('seats_'+id, seatno, val);
} catch(err) {
console.log(err)
}
}
//delete the key
async function del(id) {
try{
await client.del('seats_'+id);
} catch(err) {
console.log(err);
}
}
//export functions
module.exports = {
exists: exists,
set : set,
update : update,
get : get,
del : del
};