redis反序列化问题

报错如下:

org.springtramework.core.convert.Conversionl-aiLedtxception: failed to convert from type java.Lang.String to type java.Lang.Long to vaLue 1{"beginTime":1638954300246,"currentPage":1,"endTime":1638954900246,"pcursor":H"}1; nested exception is java.lang.NumberFormatException: For input string: "{"beginTime":1638954300246,"currentPage":1,"endTime":1638954900246,"pcursor":"

at org.springframework.core.convert.support.Conversionlltils.invokeConverter(ConversionUtils.java:43)

at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:203)

at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:187)

at org.springframework.data.redis.serializer.GenericToStringSerializerSConverter.convert(GenericToStringSerializer.java:106)

at org.springframework.data.redis.serializer.GenericToStringSerializer.deserialize(GenericToStringSerializer.java:70)

at org.springframework.data.redis.core.Abstractoperations.deserializeValue(AbstractOperations.java:315)

at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:55)

at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:204)

at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:166)

at org.springframework.data.redis.core.Abstractoperations.execute(AbstractOperations.java:88)

at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:43)

at com.czb.coupon.jobHandle.impl.JobHandle.getKsRefundRedisVO(JobHandle.java:439)

at com.czb.coupon.jobHandle.impl.JobHandle.refundEvery5Min(JobHandle.java:259)

at sun.reflect.GeneratedMethodAccessor2273.invoke(Unknowr) Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at com.xxl.job.core.handler.impl.MethodJobHandler.execute(MethodJobHandler.java:29)

at com.xxl.job.core.thread.JobThread.run(JobThread.java:152)

Caused by: java.lang.NumberFormatException: For input string: "{"beginTime":1638954300246,"currentPage":1,"endTime":1638954900246,"pcursor":"

我是这么设置key的:

Object result = redisService.getTemplate().opsForValue().get(KEY);

@Override

public RedisTemplate<String, Object> getTemplate() {

return redisTemplate;

}

@Autowired

@Qualifier("redisTemplate")

private RedisTemplate<String, Object> redisTemplate;

这样拿value:

redisService.getTemplate().opsForValue().set(KEY,"{\"value1\":\"aaa\"}");

各位大佬帮忙看看吧

补充:redis配置类如下:

    @Bean(name = "redisson")

public Redisson getTencentRedisson() {

Config config = new Config();

config.useSingleServer()

.setAddress("redis://" + host + ":" + port)

.setPassword(password)

.setDatabase(database)

//等待节点回复命令的时间。该时间从命令发送成功时开始计时。默认:3000

.setTimeout(tencentTimeout)

//如果尝试达到 retryAttempts(命令失败重试次数) 仍然不能将命令发送至某个指定的节点时,将抛出错误。如果尝试在此限制之内发送成功,则开始启用 timeout(命令等待超时) 计时。默认值:3

.setRetryAttempts(5);

return (Redisson) Redisson.create(config);

}

private RedisTemplate<String, Object> initRedis() {

RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();

redisConnectionFactory.setHostName(host);

redisConnectionFactory.setPort(port);

redisConnectionFactory.setPassword(password);

redisConnectionFactory.setDatabase(database);

redisConnectionFactory.setTimeout(timeout);

redisTemplate.setKeySerializer(new StringRedisSerializer());

redisTemplate.setValueSerializer(new StringRedisSerializer());

redisTemplate.setHashKeySerializer(new StringRedisSerializer());

redisTemplate.setHashValueSerializer(new StringRedisSerializer());

JedisPoolConfig poolConfig = new JedisPoolConfig();

poolConfig.setMaxIdle(maxIdle);

poolConfig.setMinIdle(minIdle);

poolConfig.setMaxWaitMillis(maxWait);

poolConfig.setMaxTotal(maxActive);

redisConnectionFactory.setPoolConfig(poolConfig);

redisConnectionFactory.afterPropertiesSet();

redisTemplate.setConnectionFactory(redisConnectionFactory);

return redisTemplate;

}


回答:

你的 redisTemplate 怎么实例化的,贴下代码看看呢

以上是 redis反序列化问题 的全部内容, 来源链接: utcz.com/p/944130.html

回到顶部