fixed redis cache leak issue

This commit is contained in:
strawmanbobi
2025-06-03 13:05:57 +08:00
parent f84bd13f85
commit f00d088078
6 changed files with 7 additions and 59 deletions

View File

@@ -1,50 +0,0 @@
/**
* Created by strawmanbobi
* 2016-12-24 (Xmax eve)
*/
require('../mini_poem/configuration/constants');
let Cache = require('../mini_poem/cache/redis.js');
let logger = require('../mini_poem/logging/logger4js').helper;
let Enums = require('../constants/enums');
let ErrorCode = require('../constants/error_code');
let enums = new Enums();
let errorCode = new ErrorCode();
let TicketPair = function(_cacheHost, _cachePort, _cacheAdmin, _cachePassword) {
this.cache = new Cache(_cacheHost, _cachePort, _cacheAdmin, _cachePassword);
};
TicketPair.prototype.setTicketPair = function(id, ticket, ttl, callback) {
this.cache.set(id, ticket, ttl, function(setTicketPairErr, data) {
let error = errorCode.SUCCESS;
if(setTicketPairErr !== errorCode.SUCCESS.code) {
error = errorCode.FAILED;
}
callback(error, data);
});
};
TicketPair.prototype.getTicketPair = function(id, callback) {
let error = errorCode.SUCCESS;
this.cache.get(id, false, function(getTicketPairErr, result) {
if(errorCode.SUCCESS.code !== getTicketPairErr) {
error = errorCode.FAILED;
}
callback(error, result);
});
};
TicketPair.prototype.deleteTicketPair = function(id, callback) {
let error = errorCode.SUCCESS;
this.cache.delete(id, function(deleteTicketPairErr) {
if(deleteTicketPairErr !== errorCode.SUCCESS.code) {
error = errorCode.FAILED;
}
callback(error);
});
};
module.exports = TicketPair;

View File

@@ -29,7 +29,7 @@ var Cache = function(_host, _port, _user, _password) {
Cache.prototype = Object.create(BaseCache.prototype);
Cache.prototype.set = function(key, value, ttl, callback) {
this.redisClient.set(key, value, function(err) {
this.redisClient.set(key, value, 'EX', ttl, function(err) {
if(err) {
logger.error("Redis set value failed with key " + key);
callback(errorCode.FAILED);