[Solved] Jedis connect and operate Redis error: Failed to create socket和connect timed out

error messages:

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

Reason: Unable to load class “org . slf4j . impl . staticloggerbinder”, no operation (NOP) logger implementation by default, cannot create socket, resulting in connection timeout.

Solution:

Step 1: add import dependency first (because a class cannot be loaded, it means that there is no dependency in the library, so it needs to import dependency)

<!-- 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>

Step 2: Comment out bind 127.0.0.1 on line 69 of the redis.conf configuration file. Commenting out bind 127.0.0.1 means that all client access is available, which is equivalent to bind 0.0.0.0

Step 3: Change yes to no in protected-mode yes on line 88

Step 4: Kill the redis process and restart it
ps -ef |grep redis
kill the redis process port number
redis-server . /xiaoConfig/redis-conf
redis-cli -p 6379

Step 5: Connecting to Redis in idea by manipulating jedis
finally successful:

Read More: