Q1: redis服务关闭前确认数据还是在的,重启后发现一条数据都没了,key* 查也是空的
A1: 经仔细检查发现redis.conf配置文件配置的数据存储目录配置的是dir ./ 也就是相对目录,也就是说在哪个目录执行redis-server redis.config启动命令 redis数据就会存到哪个目录,同样就会加载哪个目录下的数据文件(dump.rdb),前后两次启动命令的位置不一样导致第二次启动没有加载到(dump.rdb)文件,从而导致查不出数据
Q2:springboot 集成redis服务,redis是搭建的集群服务,本地测试都没问题,部署到服务器上后一直报错:
Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect
Caused by: java.lang.UnsupportedOperationException: null
A2: 发现问题后,想着lettuce连接池报错,连接不上,那就换成jedis吧,一通鼓捣换成了jedis连接池再部署,倒是能查出数据来了,心想什么破lettuce,还是jedis好用,然后开始缓存数据(大批量数据缓存redis用的是Pipelined管道,快速存储嘛),完犊子又报错了:
redis.clients.jedis.exceptions.JedisDataException: Cannot use Jedis when in Pipeline. Please use Pipeline or reset jedis state . 说jedis用不了Popeline(经查资料发现jedis没提供管道查询功能),你妹的用不了你不早说。。。。咱又不能不用管道,自己实现又太麻烦)
算了换回lettuce,抽丝剥茧自己重新搭了个简单的redis测试服务,丢到服务器上测试,发现竟然没报错。。。这你妹的;经对比发现我的测试服务用的springboot2.6.1 而报错的服务用的是springboot2.1.4, 另外服务器上是redis7.0,而我本地redis是3.2的
所以结论是:springboot2.1.4+lettuce+redis7.0 会报如上的异常 而springboot2.6.1+lettuce+redis7.0就不会报错,但又不能直接将springboot2.1.4 升级成springboot2.6.1,那样可能会引起其它的问题,所以直接将lettuce升级倒springboot2.6.1所使用的lettuce版本就行了如下:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <!--去掉springboot2.1.4自带的lettuce版本--> <exclusions> <exclusion> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> </exclusion> </exclusions> </dependency> <!--依赖springboot2.6.1自带的lettuce版本--> <dependency> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> <version>6.1.5.RELEASE</version> <scope>compile</scope> </dependency>
至此问题解决,收工。。