--Redis入坑--RedisPipelineException:Pipeline contained one or more invalid commands;WRONGTYPE ...
异常说明最近在写代码的时候,redis报了如下错误:org.springframework.data.redis.connection.RedisPipelineException: Pipeline contained one or more invalid commands; nested exception is io.lettuce.core.RedisCommandException:
异常说明
最近在写代码的时候,redis报了如下错误:
org.springframework.data.redis.connection.RedisPipelineException: Pipeline contained one or more invalid commands; nested exception is io.lettuce.core.RedisCommandException: WRONGTYPE Operation against a key holding the wrong kind of value
原因分析
之前的一个需求中,使用的是list作为数据结构进行存储,其存储方式为redisService.lPush(key,value),之后逻辑的变更,使得需要换成set作为数据结构进行存储,其存储方式为redisService.sadd(key,value)。发生错误的位置就是这里:
在更改数据结构存储的同时,key的键还是一样的,因为之前的键是绑定给list结构的,现在key没变,而结构换成了set,所以导致类型错误的异常。
解决方法
只需要把键重新命名为新的并且不重复于其他键即可。
总结
在使用redis进行存储的时候,数据结构最好不要随意更改,如果更改了,就需要把键重新命名一下,以防键的类型与原来的不匹配,存储从而导致发生异常。
更多推荐
所有评论(0)