这两天经过网上各种搜索,终于成功的写出了一个关于redis缓存的demo。
第一步,准备所需的jar包;
jar包版本不匹配会出现各种各样的错误,经过多次尝试,最终成功运行的jar包版本:
jedis-2.4.2.jar,
commons-pool2-2.4.2.jar,
spring-data-redis-1.3.4.RELEASE.jar,
spring-data-commons-1.8.0.RELEASE.jar,
spring用的是4.1.6.RELEASE版本,
错误:
org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection;nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:102)
解决方法:
redis禁用保护模式
进入redis命令行,禁用保护模式就可以了。
config set protected-mode "no"