-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcache.js
More file actions
40 lines (27 loc) · 831 Bytes
/
cache.js
File metadata and controls
40 lines (27 loc) · 831 Bytes
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
const Redis = require('redis');
const dotenv = require('dotenv');
dotenv.config()
const REDIS_URL = process.env.REDIS_URL || `redis://localhost:6379` || `redis://${REDIS_USERNAME}:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}`;
class Cache {
constructor() {
this.redis = null;
}
async connect() {
try {
this.redis = await Redis.createClient({
url: REDIS_URL
});
this.redis.connect()
this.redis.on('connect', () => {
console.log('Redis connected')
})
this.redis.on('error', () => {
console.log('Redis connection error')
})
} catch (error) {
console.log(error)
}
}
}
const instance = new Cache();
module.exports = instance;