1、问题:
springboot 整合 redis 获取redis值报错。
2、原因:
redis 通过客户端直接创建的 key value :
eg:set name name
因为value 不是string 类型 所以报错。
下面情况不会报错
eg:set name 1
2021-12-23 10:52:02.358 ERROR 18812 --- [io-8080-exec-10] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized token 'caoxiheng': was expecting ('true', 'false' or 'null')
at [Source: [B@3fbce49; line: 1, column: 19]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'caoxiheng': was expecting ('true', 'false' or 'null')
at [Source: [B@3fbce49; line: 1, column: 19]] with root cause
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'caoxiheng': was expecting ('true', 'false' or 'null')
at [Source: [B@3fbce49; line: 1, column: 19]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702) ~[jackson-core-2.8.11.jar:2.8.11]
3、解决方案:
1、springboot redis 保存,redis 取
2、客户端使用:
set name '"name"'
这样创建就指定了string类型。不会报错了。