【问题集】redis.clients.jedis.exceptions.JedisDataException: ERR value is not an integer or out of range

时间:2022-07-01 14:03:18

redis.clients.jedis.exceptions.JedisDataException: ERR value is not an integer or out of range

incrment方法:

设置:

 1 <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
 2         <property name="connectionFactory" ref="connectionFactory" />
 3         <property name="keySerializer">
 4             <bean
 5                 class="org.springframework.data.redis.serializer.StringRedisSerializer" />
 6         </property>
 7         <property name="valueSerializer">
 8             <bean
 9                 class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
10         </property>
11         <property name="hashKeySerializer">
12             <bean
13                 class="org.springframework.data.redis.serializer.StringRedisSerializer" />
14         </property>
15         <property name="hashValueSerializer">
16             <bean
17                 class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
18         </property>
19     </bean>

方法变动:

 1 public static Boolean setStringValueByKeyInNxModeRateLimit(String key, String value,
 2             long interval) {
 3         logger.info("进入setStringValueByKeyInNxMode:时间为"+interval);
 4         ApplicationContext context = ApplicationContextHolder.getContext();
 5         RedisTemplate<String, String> redisTemplate = (StringRedisTemplate) context
 6                 .getBean("redisTemplate");
 7         redisTemplate.setKeySerializer(new StringRedisSerializer());  9         logger.info(redisTemplate.getKeySerializer().getClass().getName()+"第二");
10         Boolean flag = redisTemplate.opsForValue().setIfAbsent(key, value);
11         logger.info("获取到的flag为:"+flag);
12         logger.info("key的过期时间为"+redisTemplate.getExpire(key));
13         if ((flag || redisTemplate.getExpire(key) == -1) && interval > 0) {
14             logger.info("重新设置key的有效期为:"+key+interval);
15             redisTemplate.expire(key, interval, TimeUnit.SECONDS);
16         }
17         return flag;
18     }