1
我的目标是从多个应用程序实例(读写访问)与Redis服务器的一般实例一起工作。我需要它在几个Web应用程序服务器之间共享Web会话ID和会话元信息。java与几个应用程序实例的redis工作
当只有一个web应用程序实例启动时,一切都很顺利,但是当第二个实例初始化时,db被刷新,所以第一个应用程序插入的数据消失了。我尝试了两种方式建立连接:
弹簧
ApplicationContext context = new ClassPathXmlApplicationContext(
config.getString(Constants.REDIS_CONFIG_FILE));
this.redisTemplate = (RedisTemplate) context.getBean("redisTemplate");
<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:use-pool="true" p:host-name="${oiosaml-sp.sessionhandler.redis.url}"
p:port="${oiosaml-sp.sessionhandler.redis.port}"/>
<!-- redis template definition -->
<bean id="redisTemplate"
class="org.springframework.data.redis.core.RedisTemplate"
p:connection-factory-ref="jedisConnectionFactory"/>
与jedis
String redisUrl = config.getString(Constants.REDIS_URL);
String redisPort = config.getString(Constants.REDIS_PORT);
if (redisUrl == null || redisPort == null) {
throw new IllegalArgumentException(
PROPERTY_IS_NOT_SET_ERROR_MESSAGE);
}
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(MAX_CONNECTION_AMOUNT);
this.pool = new JedisPool(poolConfig, redisUrl,
Integer.parseInt(redisPort));
但在这两种变型我有同样的问题,即db是在冲洗时从第二个实例连接应用程序已建立。在这种情况下,看起来redis-server无法正常工作。我究竟做错了什么?
你说得对。刚才意外发现了一个问题。这是我的SP过滤器会话处理程序的实现,它使用我的redis连接池。内置过滤器resetReplayProtection方法在应用程序初始化期间被调用,并刷新我的数据库。无论如何,谢谢您的参与。 – JonathanLivingston