-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedisProgress.js
More file actions
45 lines (40 loc) · 1.03 KB
/
Copy pathRedisProgress.js
File metadata and controls
45 lines (40 loc) · 1.03 KB
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
const redis = require('redis');
const client = redis.createClient();
(async () => {
try {
await client.connect();
console.log('Connected to Redis');
} catch (error) {
console.error('Redis connection error:', error);
}
})();
const setProgress = async (userId, status) => {
try {
await client.set(userId, status);
} catch (error) {
console.error('Error setting progress:', error);
}
};
const getProgress = async (userId, callback) => {
try {
const result = await client.get(userId);
callback(result || "No progress yet");
} catch (error) {
console.error('Error getting progress:', error);
callback("Error Getting Progress");
}
};
// Consider adding a function to close the client when done
const closeConnection = async () => {
try {
await client.quit();
console.log('Redis client closed');
} catch (error) {
console.error('Error closing Redis client:', error);
}
};
module.exports = {
setProgress,
getProgress,
closeConnection, // export the close function if needed
};