错误

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
Exception in thread "main"redis.clients.jedis.exceptions.JedisConnectionException: Failed to create socket.
java.net.SocketTimeoutException: connect timed out

原因: 无法加载类“org . slf4j . impl . staticloggerbinder”,默认无操作(NOP)记录器实施,无法创建socket,导致连接超时

解决办法:

第一步: 先添导入依赖 (因为无法加载某个类,说明库里面没有,需要导入依赖)

<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>3.9.0</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.68.sec10</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-nop</artifactId>
    <version>1.7.6</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>2.0.0-alpha7</version>
</dependency>

第二步: 将redis.conf配置文件中第69行的bind 127.0.0.1注释掉。注释掉 bind 127.0.0.1,意味着所有客户端访问都可访问,相当于 bind 0.0.0.0
在这里插入图片描述

第三步:第88行的protected-mode yes中的yes改为no
在这里插入图片描述

第四步: 杀掉redis进程,并重新启动
ps -ef |grep redis
kill redis的进程端口号
redis-server ./xiaoConfig/redis-conf
redis-cli -p 6379
在这里插入图片描述

第五步: 在idea中通过操作jedis连接Redis
在这里插入图片描述
最后成功:
在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐