pull/1/merge
wangdongxun 2016-11-25 18:29:52 +00:00 committed by GitHub
commit c9a616b908
7 changed files with 49 additions and 12 deletions

14
pom.xml
View File

@ -43,5 +43,19 @@
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<!--tomcat lib-->
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.42</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-servlet-api -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.42</version>
</dependency>
</dependencies>
</project>

View File

@ -40,3 +40,8 @@ Steps to be done,
Note:
* The Redis session manager supports, both single redis master and redis cluster based on the redis.properties configuration.
modify explain:
* add redis select database
* repair redis session time unit bug,timeout=session.getMaxInactiveInterval(),unit =seconds

View File

@ -2,5 +2,6 @@
redis.hosts=127.0.0.1:6379
# Redis Password
redis.password=
redis.db=0
# set true to enable redis cluster mode
redis.cluster.enabled=false

View File

@ -57,6 +57,7 @@ public class RedisManager
poolConfig.setNumTestsPerEvictionRun(testNumPerEviction);
long timeBetweenEviction = Long.parseLong(properties.getProperty(RedisConstants.TIME_BETWEENEVICTION, RedisConstants.DEFAULT_TIME_BETWEENEVICTION_VALUE));
poolConfig.setTimeBetweenEvictionRunsMillis(timeBetweenEviction);
int database = Integer.parseInt(properties.getProperty(RedisConstants.DATABASE, "0"));
String hosts = properties.getProperty(RedisConstants.HOSTS, Protocol.DEFAULT_HOST.concat(":").concat(String.valueOf(Protocol.DEFAULT_PORT)));
String host = null;
int port = 0;
@ -74,8 +75,10 @@ public class RedisManager
if (password == null || password == "" || password.isEmpty()) {
pool = new JedisPool(poolConfig, host, port);
} else {
pool = new JedisPool(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, password);
// pool = new JedisPool(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, password);
pool =new JedisPool(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, password,database);
}
}
public Jedis getJedis() {

View File

@ -50,6 +50,7 @@ public class RequestSessionCacheFactory
resourceStream = null;
properties = new Properties();
File file = new File(System.getProperty("catalina.base").concat(File.separator).concat("conf").concat(File.separator).concat(RedisConstants.REDIS_DATA_CACHE_PROPERTIES_FILE));
log.info("redis properties:"+file.getPath().toString());
if (file.exists()) {
resourceStream = new FileInputStream(file);
}

View File

@ -23,6 +23,7 @@ public class RedisConstants
public static final String TIME_BETWEENEVICTION = "redis.time.betweenEviction";
public static final String HOSTS = "redis.hosts";
public static final String PASSWORD = "redis.password";
public static final String DATABASE = "redis.db";
public static final String IS_CLUSTER_ENABLED = "redis.cluster.enabled";
// Redis property default values

View File

@ -133,8 +133,8 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
} catch (Exception e) {
log.error("Error while initializing serializer/rediscache", e);
}
log.info("The sessions will expire after " + (getContext().getSessionTimeout() * 60) + " seconds");
getContext().setDistributable(true);
// log.info("The sessions will expire after " + (getContext().getSessionTimeout() * 60) + " seconds");
// getContext().setDistributable(true);
}
@Override
@ -162,7 +162,7 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
customSession.setNew(true);
customSession.setValid(true);
customSession.setCreationTime(System.currentTimeMillis());
customSession.setMaxInactiveInterval((getContext().getSessionTimeout() * 60));
// customSession.setMaxInactiveInterval((getContext().getSessionTimeout() * 60));
customSession.setId(sessionId);
customSession.tellNew();
}
@ -229,7 +229,9 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
@Override
public void remove(Session session, boolean update) {
requestSessionCacheUtils.deleteKey(session.getId());
// expire after 10 seconds
requestSessionCacheUtils.expire(session.getId(),10);
// requestSessionCacheUtils.deleteKey(session.getId());
}
@Override
@ -262,7 +264,7 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
serializer.deserializeSessionData(data, customSession, metadata);
customSession.setId(id);
customSession.setNew(false);
customSession.setMaxInactiveInterval((getContext().getSessionTimeout() * 60));
// customSession.setMaxInactiveInterval((getContext().getSessionTimeout() * 60));
customSession.access();
customSession.setValid(true);
customSession.resetDirtyTracking();
@ -296,8 +298,16 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
currentSessionSerializationMetadata.set(updatedSerializationMetadata);
currentSessionIsPersisted.set(true);
}
log.trace("Setting expire timeout on session [" + customSession.getId() + "] to " + (getContext().getSessionTimeout() * 60));
requestSessionCacheUtils.expire(customSession.getId(), (getContext().getSessionTimeout() * 60));
//time uite seconds
int timeOut=session.getMaxInactiveInterval();
if(timeOut<1){
timeOut=1800;
}
// log.trace("Setting expire timeout on session [" + customSession.getId() + "] to " + (getContext().getSessionTimeout() * 60));
// requestSessionCacheUtils.expire(customSession.getId(), (getContext().getSessionTimeout() * 60));
log.trace("Setting expire timeout on session [" + customSession.getId() + "] to " + timeOut+"seconds");
requestSessionCacheUtils.expire(customSession.getId(), timeOut);
} catch (IOException e) {
log.error("Error occured while storing the session object into redis", e);
}
@ -332,10 +342,12 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
*/
private void initializeSessionSerializer() throws Exception {
serializer = new SessionDataSerializer();
Loader loader = null;
if (getContext() != null) {
loader = getContext().getLoader();
}
// Loader loader = null;
//
// if (getContext() != null) {
// loader = getContext().getLoader();
// }
Loader loader =this.getContainer().getLoader();
ClassLoader classLoader = null;
if (loader != null) {
classLoader = loader.getClassLoader();