-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis.js
36 lines (25 loc) · 823 Bytes
/
redis.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
import { createClient } from 'redis';
const client = createClient({
password: 'PtaC3hKBu1u6d4h4YFBTSwbXaixgQAze',
socket: {
host: 'redis-17235.c321.us-east-1-2.ec2.cloud.redislabs.com',
port: 17235
}
});
client.on('error', err => {
console.log('Redis Client Error', err);
// Handle the error gracefully; you might choose to log it and continue execution
});
const connectToRedis = async () => {
await client.connect().catch(err => {
console.error('Error connecting to Redis:', err);
// Handle the connection error here as well
});
};
const setCache = async (key, data) => {
await client.set(key, JSON.stringify(data));
};
const getCache = async (key) => {
return await client.get(key);
};
export { client, connectToRedis, setCache, getCache };