Redis database and timeout changes..

1.x 1.1.1
Ranjith Manickam -T (ranmanic - COGNIZANT TECHNOLOGY SOLUTIONS INDIA PVT LTD at Cisco) 2016-11-26 00:04:35 +05:30
parent 897b15ac10
commit 6239e6f12b
5 changed files with 23 additions and 11 deletions

View File

@ -1,6 +1,14 @@
# redis hosts ex: 127.0.0.1:6379, 127.0.0.2:6379, 127.0.0.2:6380, .... # redis hosts ex: 127.0.0.1:6379, 127.0.0.2:6379, 127.0.0.2:6380, ....
redis.hosts=127.0.0.1:6379 redis.hosts=127.0.0.1:6379
# Redis Password # Redis Password
redis.password= redis.password=
# set true to enable redis cluster mode # set true to enable redis cluster mode
redis.cluster.enabled=false redis.cluster.enabled=false
# Redis database (default 0)
#redis.database=0
# Redis connection timeout (default 2000)
#redis.timeout=2000

View File

@ -59,7 +59,8 @@ public class RedisClusterManager
poolConfig.setNumTestsPerEvictionRun(testNumPerEviction); poolConfig.setNumTestsPerEvictionRun(testNumPerEviction);
long timeBetweenEviction = Long.parseLong(properties.getProperty(RedisConstants.TIME_BETWEENEVICTION, RedisConstants.DEFAULT_TIME_BETWEENEVICTION_VALUE)); long timeBetweenEviction = Long.parseLong(properties.getProperty(RedisConstants.TIME_BETWEENEVICTION, RedisConstants.DEFAULT_TIME_BETWEENEVICTION_VALUE));
poolConfig.setTimeBetweenEvictionRunsMillis(timeBetweenEviction); poolConfig.setTimeBetweenEvictionRunsMillis(timeBetweenEviction);
jedisCluster = new JedisCluster(getJedisClusterNodesSet(properties.getProperty(RedisConstants.HOSTS, Protocol.DEFAULT_HOST.concat(":").concat(String.valueOf(Protocol.DEFAULT_PORT)))), poolConfig); int timeout = Integer.parseInt(properties.getProperty(RedisConstants.TIMEOUT, String.valueOf(Protocol.DEFAULT_TIMEOUT)));
jedisCluster = new JedisCluster(getJedisClusterNodesSet(properties.getProperty(RedisConstants.HOSTS, Protocol.DEFAULT_HOST.concat(":").concat(String.valueOf(Protocol.DEFAULT_PORT)))), (timeout < Protocol.DEFAULT_TIMEOUT ? Protocol.DEFAULT_TIMEOUT : timeout), poolConfig);
} }
/** /**

View File

@ -71,11 +71,9 @@ public class RedisManager
} }
} }
String password = properties.getProperty(RedisConstants.PASSWORD); String password = properties.getProperty(RedisConstants.PASSWORD);
if (password == null || password == "" || password.isEmpty()) { int database = Integer.parseInt(properties.getProperty(RedisConstants.DATABASE, String.valueOf(Protocol.DEFAULT_DATABASE)));
pool = new JedisPool(poolConfig, host, port); int timeout = Integer.parseInt(properties.getProperty(RedisConstants.TIMEOUT, String.valueOf(Protocol.DEFAULT_TIMEOUT)));
} else { pool = new JedisPool(poolConfig, host, port, (timeout < Protocol.DEFAULT_TIMEOUT ? Protocol.DEFAULT_TIMEOUT : timeout), ((password == null || password == "" || password.isEmpty()) ? null : password), database);
pool = new JedisPool(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, password);
}
} }
public Jedis getJedis() { public Jedis getJedis() {

View File

@ -24,6 +24,8 @@ public class RedisConstants
public static final String HOSTS = "redis.hosts"; public static final String HOSTS = "redis.hosts";
public static final String PASSWORD = "redis.password"; public static final String PASSWORD = "redis.password";
public static final String IS_CLUSTER_ENABLED = "redis.cluster.enabled"; public static final String IS_CLUSTER_ENABLED = "redis.cluster.enabled";
public static final String DATABASE = "redis.database";
public static final String TIMEOUT = "redis.timeout";
// Redis property default values // Redis property default values
public static final String DEFAULT_MAX_ACTIVE_VALUE = "10"; public static final String DEFAULT_MAX_ACTIVE_VALUE = "10";

View File

@ -229,7 +229,7 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
@Override @Override
public void remove(Session session, boolean update) { public void remove(Session session, boolean update) {
requestSessionCacheUtils.deleteKey(session.getId()); requestSessionCacheUtils.expire(session.getId(), 10);
} }
@Override @Override
@ -296,8 +296,11 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
currentSessionSerializationMetadata.set(updatedSerializationMetadata); currentSessionSerializationMetadata.set(updatedSerializationMetadata);
currentSessionIsPersisted.set(true); currentSessionIsPersisted.set(true);
} }
log.trace("Setting expire timeout on session [" + customSession.getId() + "] to " + (getContext().getSessionTimeout() * 60));
requestSessionCacheUtils.expire(customSession.getId(), (getContext().getSessionTimeout() * 60)); int timeout = getContext().getSessionTimeout() * 60;
timeout = timeout < 1800 ? 1800 : timeout;
log.trace("Setting expire timeout on session [" + customSession.getId() + "] to " + timeout);
requestSessionCacheUtils.expire(customSession.getId(), timeout);
} catch (IOException e) { } catch (IOException e) {
log.error("Error occured while storing the session object into redis", e); log.error("Error occured while storing the session object into redis", e);
} }