RedisTemplate
报错:
org.springframework.dao.InvalidDataAccessApiUsageException: WRONGTYPE Operation against a key holding the wrong kind of value; nested exception is redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value
······
Caused by: redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value
at redis.clients.jedis.Protocol.processError(Protocol.java:142)
at redis.clients.jedis.Protocol.process(Protocol.java:176)
at redis.clients.jedis.Protocol.read(Protocol.java:230)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:352)
at redis.clients.jedis.Connection.getIntegerReply(Connection.java:294)
at redis.clients.jedis.BinaryJedis.sadd(BinaryJedis.java:1742)
at org.springframework.data.redis.connection.jedis.JedisInvoker.lambda$just$5(JedisInvoker.java:130)
at org.springframework.data.redis.connection.jedis.JedisConnection.lambda$doInvoke$2(JedisConnection.java:181)
at org.springframework.data.redis.connection.jedis.JedisConnection.doWithJedis(JedisConnection.java:824)
主要是这个:
WRONGTYPE Operation against a key holding the wrong kind of value
有现成答案 直接看这个或许就能解决
https://blog.youkuaiyun.com/qq_34246965/article/details/123105830
我来复现我的问题。
配置和代码:
测试类运行后报错
然后神奇的事发生了
在编译器报错的地方打个断点,debug运行,然后… 成功运行
试了很多次都是一样
肯定不是偶然!
把前面这个 用 string 的注释了 再跑就OK
结论
为什么要用同一个 Key?
因为 redis 里有相同的key了,但是结构类型不一样 所以报这个错
类似 Map<String, List>
Value 明明是 List 你却存String?