27 lines
420 B
JavaScript
27 lines
420 B
JavaScript
const Redis = require("ioredis");
|
|
|
|
class Cache {
|
|
constructor(options) {
|
|
this.redis = new Redis(options);
|
|
}
|
|
|
|
async set(key, value) {
|
|
try {
|
|
await this.redis.set(key, value);
|
|
} catch (err) {
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
async get(key) {
|
|
try {
|
|
const data = await this.redis.get(key);
|
|
return JSON.parse(data);
|
|
} catch (err) {
|
|
throw err;
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = Cache;
|