-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathredis-client.js
51 lines (43 loc) · 1.36 KB
/
redis-client.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
const redis = require('redis');
const { promisify } = require('util');
if (process.env.NODE_ENV !== 'production') require('dotenv').config();
async function RedisClient() {
return new Promise((resolve, reject) => {
const client = redis.createClient(process.env.REDIS_URL);
client.on('connect', () => {
console.error('REDIS CONNECTED');
});
client.on('ready', () => {
console.error('REDIS READY');
resolve({
get: promisify(client.get).bind(client),
set: promisify(client.set).bind(client),
quit: promisify(client.quit).bind(client),
});
});
client.on('end', () => {
console.error('REDIS END');
// reject('end');
});
client.on('reconnecting', () => {
console.error('REDIS RECONNECTING');
// reject('end');
});
client.on('disconnected', () => {
console.error('REDIS DISCONNECTED');
reject('disconnected');
});
client.on('error', (error) => {
console.error('REDIS ERROR');
console.error(error);
reject('error');
process.exit(42);
});
client.on('warning', () => {
console.error('REDIS WARNING');
// reject('warning');
console.error('client will emit warning when password was set but none is needed and if a deprecated option/function/similar is used.');
});
});
}
module.exports = { RedisClient };