spring redis 相关配置总结
好久都没有更新过日志了,最近也应接不暇的在踩雷!今天模拟上线,趁现在写写东西。吼吼吼……
ps:第一次用这个编辑器 感觉还不错!
- spring redis 整合配置
- spring redis pom配置
spring redis 整合的相关配置
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!-- 最大分配的对象数 -->
<property name="maxTotal" value="${redis.pool.maxTotal}" />
<!-- 最大能够保持idel状态的对象数 -->
<property name="maxIdle" value="${redis.pool.maxIdle}" />
<!-- 最小能够保持idel状态的对象数 -->
<property name="minIdle" value="${redis.pool.minIdle}" />
<!-- 当调用borrow Object方法时,是否进行有效性检查 -->
<property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />
</bean>
<!-- Jedis ConnectionFactory 数据库连接配置 -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.hostname}" />
<property name="port" value="${redis.port}" />
<property name="poolConfig" ref="jedisPoolConfig" />
<property name="database" value="${redis.dbindex}" />
</bean>
<!-- redis template definition -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="hashKeySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="hashValueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
</property>
</bean>
spring redis pom 配置
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>${spring-data-redis.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${redis.version}</version>
</dependency>
@author 这个还是有bug 第一次有输入法的时候 总是向上跳三行。
redis 生成序列号 自增长
String snKey = "ACT_SERIALNUMBER_ERROR_" + sn;
Long value = redisTemplate.opsForValue().increment(snKey, 1);
redisTemplate.expire(snKey, 1, TimeUnit.DAYS);//设置一天后过期
我一开始以为要设置一个初始值结果怎么设置就不对。类型转换异常或者
ERR value is not an integer or out of range
原来什么也不设置 直接用key 就好