我使用的是spring框架,websocket 1秒向前端推送一次房间信息,房间信息需要从redis中获取,程序运行不定什么时候redis对应key中取出的值就变成'OK'了,但是通过redisDesktopManager查看里面的值是1,为什么会这样? 谢谢各位了。
这是redisDesktopManager工具查看key中的值:
出错时debug取出的值:
redis.conf:
<!-- 缓存的层级 -->
<context:component-scan base-package="com.bibi"/>
<!-- 引入redis配置 -->
<context:property-placeholder location="classpath:conf/properties/redis.properties" ignore-unresolvable="true"/>
<cache:annotation-driven cache-manager="cacheManager"/>
<!-- Redis 配置 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="${redis.maxTotal}"/>
<property name="maxIdle" value="${redis.maxIdle}"/>
<property name="maxWaitMillis" value="${redis.maxWaitMillis}"/>
<property name="testOnBorrow" value="${redis.testOnBorrow}"/>
</bean>
<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
<constructor-arg name="poolConfig" ref="jedisPoolConfig"/>
<constructor-arg name="host" value="${redis.host}"/>
<constructor-arg name="port" value="${redis.port}" type="int"/>
<constructor-arg name="timeout" value="${redis.maxWaitMillis}" type="int"/>
<constructor-arg name="password" value="#{'${redis.password}'!=''?'${redis.password}':null}"/>
<constructor-arg name="database" value="${redis.db}" type="int"/>
</bean>
<!-- reids session共享 -->
<!-- <bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"
p:maxInactiveIntervalInSeconds="1800"/>-->
<!-- redis单节点数据库连接配置 -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.password}"
p:pool-config-ref="jedisPoolConfig"/>
<!-- redisTemplate配置,redisTemplate是对Jedis的对redis操作的扩展,有更多的操作,封装使操作更便捷 -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"/>
</bean>
<!-- spring自己的缓存管理器,这里定义了缓存位置名称 ,即注解中的value -->
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<!-- 这里可以配置多个redis -->
<!-- <bean class="com.cn.util.RedisCache">
<property name="redisTemplate" ref="redisTemplate" />
<property name="name" value="default"/>
</bean> -->
<bean class="com.bibi.base.util.redis.RedisCache">
<property name="redisTemplate" ref="redisTemplate"/>
<property name="name" value="user"/>
<!-- common名称要在类或方法的注解中使用 -->
</bean>
<bean class="com.bibi.base.util.redis.RedisCache">
<property name="redisTemplate" ref="redisTemplate"/>
<property name="name" value="system"/>
</bean>
<bean class="com.bibi.base.util.redis.RedisCache">
<property name="redisTemplate" ref="redisTemplate"/>
<property name="name" value="purse"/>
</bean>
<bean class="com.bibi.base.util.redis.RedisCache">
<property name="redisTemplate" ref="redisTemplate"/>
<property name="name" value="school"/>
</bean>
<bean class="com.bibi.base.util.redis.RedisCache">
<property name="redisTemplate" ref="redisTemplate"/>
<property name="name" value="match"/>
</bean>
<bean class="com.bibi.base.util.redis.RedisCache">
<property name="redisTemplate" ref="redisTemplate"/>
<property name="name" value="chat"/>
</bean>
<bean class="com.bibi.base.util.redis.RedisCache">
<property name="redisTemplate" ref="redisTemplate"/>
<property name="name" value="system"/>
</bean>
<bean class="com.bibi.base.util.redis.RedisCache">
<property name="redisTemplate" ref="redisTemplate"/>
<property name="name" value="assemble"/>
</bean>
<bean class="com.bibi.base.util.redis.RedisCache">
<property name="redisTemplate" ref="redisTemplate"/>
<property name="name" value="private_room"/>
</bean>
</set>
</property>
</bean>
redis.properties:
#redis的服务器地址
redis.host=127.0.0.1
#redis的服务端口
redis.port=6379
#密码
redis.password=
#链接数据库
redis.db=0
#客户端超时时间单位是毫秒
#redis.timeout=1000000
#最大连接数
redis.maxTotal=300
#最大空闲数
redis.maxIdle=100
#最大建立连接等待时间
redis.maxWaitMillis=5000
#指明是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个
redis.testOnBorrow=true
#缓存生命周期 秒数
redis.defaultExpiration=300
https://github.com/xetorthio/... this is a jedis bug, the author of jedis is drop the database,close the issue and run away, so the solution is change a new redis connection pool .