fixed redis cache leak issue
This commit is contained in:
@@ -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;
|
|
||||||
2
console/mini_poem/cache/redis.js
vendored
2
console/mini_poem/cache/redis.js
vendored
@@ -29,7 +29,7 @@ var Cache = function(_host, _port, _user, _password) {
|
|||||||
Cache.prototype = Object.create(BaseCache.prototype);
|
Cache.prototype = Object.create(BaseCache.prototype);
|
||||||
|
|
||||||
Cache.prototype.set = function(key, value, ttl, callback) {
|
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) {
|
if(err) {
|
||||||
logger.error("Redis set value failed with key " + key);
|
logger.error("Redis set value failed with key " + key);
|
||||||
callback(errorCode.FAILED);
|
callback(errorCode.FAILED);
|
||||||
|
|||||||
8
server/.idea/modules.xml
generated
8
server/.idea/modules.xml
generated
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/private-server.iml" filepath="$PROJECT_DIR$/private-server.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Repository;
|
|||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filename: IDecodeSessionRepositoryImpl.java
|
* Filename: IDecodeSessionRepositoryImpl.java
|
||||||
@@ -38,6 +39,7 @@ public class DecodeSessionRepositoryImpl implements IDecodeSessionRepository {
|
|||||||
|
|
||||||
public void add(final String decodeSessionId, Integer binaryId) {
|
public void add(final String decodeSessionId, Integer binaryId) {
|
||||||
hashOperations.put(KEY, decodeSessionId, binaryId);
|
hashOperations.put(KEY, decodeSessionId, binaryId);
|
||||||
|
redisTemplate.expire(decodeSessionId, 7 , TimeUnit.DAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(String decodeSessionId) {
|
public void delete(String decodeSessionId) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Repository;
|
|||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filename: IIRBinaryRepositoryImpl.java
|
* Filename: IIRBinaryRepositoryImpl.java
|
||||||
@@ -41,6 +42,7 @@ public class IRBinaryRepositoryImpl implements IIRBinaryRepository {
|
|||||||
|
|
||||||
public void add(Integer id, RemoteIndex remoteIndex) {
|
public void add(Integer id, RemoteIndex remoteIndex) {
|
||||||
hashOperations.put(KEY, id, remoteIndex);
|
hashOperations.put(KEY, id, remoteIndex);
|
||||||
|
redisTemplate.expire(Integer.toString(id), 7 , TimeUnit.DAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(final Integer id) {
|
public void delete(final Integer id) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Repository;
|
|||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filename: UserAppRepositoryImpl.java
|
* Filename: UserAppRepositoryImpl.java
|
||||||
@@ -39,6 +40,7 @@ public class UserAppRepositoryImpl implements IUserAppRepository {
|
|||||||
|
|
||||||
public void add(Integer id, String token) {
|
public void add(Integer id, String token) {
|
||||||
hashOperations.put(KEY, token, id);
|
hashOperations.put(KEY, token, id);
|
||||||
|
redisTemplate.expire(token, 7 , TimeUnit.DAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(final String token) {
|
public void delete(final String token) {
|
||||||
|
|||||||
Reference in New Issue
Block a user