redis读取缓存数据时出现数值序列化异常

redis读取缓存数据时出现异常,异常信息如下:Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: WRONGTYPE Operation against a key holding the wrong kind of value,翻译出来的意思就是,redis命令执行异常:错误的操作类型对应的key保存了错误的值类型,认真核对后发现是缓存中设置的为 string类型的value值,而在应用中则采用了list的方式进行数据的获取,造成操作类型和value 的类型不匹配的问题,后来就把redis中设置的value类型改成了list,然后再次操作出现新的异常,异常信息如下:

Could not read JSON: Invalid UTF-8 start byte 0x80

at [Source: (byte[])"“11.20.207.21”"; line: 1, column: 3]; nested exception is com.fasterxml.jackson.core.JsonParseException: Invalid UTF-8 start byte 0x80

at [Source: (byte[])"“11.20.207.21”"; line: 1, column: 3]

其初是以为redisTemplate对值进行序列化的时候是按照json格式进行设置的,所以无法正常序列化字符串格式(PS:当时有点犯浑),然后将字符串改成了jsonObject格式"{"ip":"11.20.207.21"}",再次操作出现了新的异常,异常信息如下:

Could not read JSON: Unexpected token (START_OBJECT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class java.lang.Object

at [Source: (byte[])"{"ip":"11.20.207.21"}"; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (START_OBJECT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class java.lang.Object

at [Source: (byte[])"{"ip":"11.20.207.21"}"; line: 1, column: 1]

然后没认真分析只看到 need JSON Array to contain贸然认为是是需要JSONArray的值类型,然后就把jsonObject类型改成了JSONArray格式{ "data": [ { "ip": "1.202.237.218" } ]}",再次操作仍出现异常,异常信息如下:

Could not read JSON: Unexpected token (START_OBJECT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class java.lang.Object

at [Source: (byte[])"{  "data": [ { "ip": "11.20.207.21"} ]}"; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (START_OBJECT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class java.lang.Objectat [Source: (byte[])"{    "data": [  {"ip": "11.20.207.21" } ]}"; line: 1, column: 1]

无奈只下只能把配置删除手动重新配置了一次,再次操作一切OK ^_^! 当是有点百撕不得其姐,今日复盘才发现问题根本原因:当时配置value时 值是从微信直接复制进来的,复制的时候可能复制了一个特殊字符进来,所以造成应用解析出现异常,其实异常提示已经很明确喽“[Source: (byte[])"“11.20.207.21”"; line: 1, column: 3]”,标红的地方就是特殊字条,只是肉眼看不到而已,再加上当时犯浑这么明显的提示都没分析出来*_*!,白白浪费大好时光啊。

特记录下来已飨回忆。

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值