一次 redis 的连接过程

1、类库要匹配,我全用最新的,因为我原本spring的版本就比较低(3.2.14),结果项目就是启动不了,总结了两组可以启动的jar

A组:
commons-pool2-2.4.2.jar
jedis-2.8.1.jar
spring-data-commons-1.12.1.RELEASE.jar
spring-data-keyvalue-1.1.1.RELEASE.jar
spring-data-redis-1.7.1.RELEASE.jar

B组:
commons-pool2-2.8.0.jar
jedis-2.9.3.jar
spring-data-commons-2.1.18.RELEASE.jar
spring-data-keyvalue-2.1.18.RELEASE.jar
spring-data-redis-1.6.6.RELEASE.jar

2、redis 端口要正确,windows下默认端口是 6379

3、redis 部署在另一台电脑,所以要允许远程访问,找到对应的配置文件,开启bind:
redis.windows-service.conf 大概在56行左右
bind 127.0.0.1 192.168.1.55

4、把 redis  在windows下的安装目录copy到本地,用以下命令跑跑看通不通
redis-cli -h 192.168.1.55 -p 6379
auth password
keys *
或者用 telnet 试下通不通
telnet 192.168.1.55 6379

5、写一段java小代码看看通不通
    public static void main(String [] args) {
        Jedis jedis = new Jedis("192.168.1.55");       
        jedis.auth("password");
        jedis.set("firstKey", "hello redis!");        
        jedis.close();
    }

6、Could not get a resource from the pool
JedisConnectionFactory 有一个参数 usePool:是否使用连接池,先设置为false,返回  NOAUTH Authentication required,原来是 JedisConnectionFactory 中的参数 password 没有设置,加上之后,再把 usePool 设置为 true,问题解决

参考链接

https://help.aliyun.com/knowledge_detail/71967.html?spm=a2c4g.11186623.2.27.345b39e9vLkWWz#cc1

https://mvnrepository.com/         


版权声明:本文为wuyou原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。