mirror of
https://github.com/PretendoNetwork/juxtaposition-ui.git
synced 2026-04-24 15:27:00 -05:00
fix: redis cache expiration not working
Some checks failed
Build and Publish Docker Image / build-publish (push) Has been cancelled
Some checks failed
Build and Publish Docker Image / build-publish (push) Has been cancelled
This commit is contained in:
parent
c87def593f
commit
5a1cc6e583
1124
src/database.js
1124
src/database.js
File diff suppressed because it is too large
Load Diff
|
|
@ -1,53 +1,55 @@
|
|||
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const redis = require('redis');
|
||||
const logger = require('./logger');
|
||||
const config = require('../config.json');
|
||||
const { host, port } = config.redis;
|
||||
|
||||
const redisClient = redis.createClient({
|
||||
url: `redis://${host}:${port}`
|
||||
});
|
||||
|
||||
redisClient.on('error', (error) => {
|
||||
logger.error(error);
|
||||
});
|
||||
|
||||
redisClient.on('connect', () => {
|
||||
logger.success('Redis connected');
|
||||
});
|
||||
|
||||
async function setValue(key, value, expireTime) {
|
||||
if (!redisClient.isOpen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await redisClient.set(key, value, 'EX', expireTime);
|
||||
return true;
|
||||
}
|
||||
|
||||
async function getValue(key) {
|
||||
if (!redisClient.isOpen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const result = await redisClient.get(key);
|
||||
return result;
|
||||
}
|
||||
|
||||
async function removeValue(key) {
|
||||
if (!redisClient.isOpen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await redisClient.del(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
redisClient,
|
||||
setValue,
|
||||
getValue,
|
||||
removeValue
|
||||
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const redis = require('redis');
|
||||
const logger = require('./logger');
|
||||
const config = require('../config.json');
|
||||
const { host, port } = config.redis;
|
||||
|
||||
const redisClient = redis.createClient({
|
||||
url: `redis://${host}:${port}`
|
||||
});
|
||||
|
||||
redisClient.on('error', (error) => {
|
||||
logger.error(error);
|
||||
});
|
||||
|
||||
redisClient.on('connect', () => {
|
||||
logger.success('Redis connected');
|
||||
});
|
||||
|
||||
async function setValue(key, value, expireTime) {
|
||||
if (!redisClient.isOpen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await redisClient.set(key, value, 'EX', expireTime);
|
||||
// Seems to be a library bug, so we have to manually set the expire time
|
||||
await redisClient.expire(key, expireTime);
|
||||
return true;
|
||||
}
|
||||
|
||||
async function getValue(key) {
|
||||
if (!redisClient.isOpen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const result = await redisClient.get(key);
|
||||
return result;
|
||||
}
|
||||
|
||||
async function removeValue(key) {
|
||||
if (!redisClient.isOpen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await redisClient.del(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
redisClient,
|
||||
setValue,
|
||||
getValue,
|
||||
removeValue
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user