解决:Redis:java.util.NoSuchElementException: Unable to validate object at

    在 Java 使用 Redis 的过程中遇见了一个问题,

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool at
Caused by: java.util.NoSuchElementException: Unable to validate object at

    这个问题是说拿不到 Redis 的链接,因为 validate 通不过。登录一个客户端,手动 ping 一下

127.0.0.1:6379> ping
(error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.

    貌似是 RDB 持久化的问题。

    解决方法,使用 redis-cli 修改 rdb 目录

CONFIG SET dir /tmp/redis_data
CONFIG SET dbfilename temp.rdb

    重启 redis-server,问题解决!

    

    上面的解决方法需要每次启动 server 都要修改 rdb 的路径。

    另一种解决方法是直接修改 redis.conf 文件,修改如下两行:

    

dir /tmp/redis_data    #./ -->  /tmp/redis_data
dbfilename temp.rdb   #

    启动 redis-server

/opt/redis-3.2.1/src/redis-server /etc/redis/redis.conf

    问题解决!

    OK!