dockerredisjedis

redis failed to create socket


Faced a problem with redis connection. Host and port configured, redis container in docker worked fine and I have no idea why this exception occured.

How I run this test:

run docker container with redis -> get into redis cli and do "redis-server"

cli screenshot:

cli screenshot

after what I run a test.

P.S. redis worked fine in console

redis console:

redis console

test

@SpringBootTest
class MessengerApplicationTests {

    @Test
    void contextLoads() {
        Jedis jedis = new Jedis();

        System.out.println(jedis.keys("*"));
    }

}

exception

Failed to create socket.
    redis.clients.jedis.exceptions.JedisConnectionException: Failed to create socket.
        at app//redis.clients.jedis.DefaultJedisSocketFactory.createSocket(DefaultJedisSocketFactory.java:110)
        at app//redis.clients.jedis.Connection.connect(Connection.java:226)
        at app//redis.clients.jedis.BinaryClient.connect(BinaryClient.java:140)
        at app//redis.clients.jedis.Connection.sendCommand(Connection.java:163)
        at app//redis.clients.jedis.BinaryClient.keys(BinaryClient.java:248)
        at app//redis.clients.jedis.Client.keys(Client.java:130)
        at app//redis.clients.jedis.Jedis.keys(Jedis.java:380)
        at app//com.microservice.messenger.MessengerApplicationTests.contextLoads(MessengerApplicationTests.java:22)
        at java.base@16.0.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base@16.0.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
        at java.base@16.0.1/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base@16.0.1/java.lang.reflect.Method.invoke(Method.java:567)
        at app//org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
        at app//org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)

application.yml

server:
  port: ${SERVER_PORT:3031}

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/reg_auth_db
    username: postgres
    password: postgres

  flyway:
    url: jdbc:postgresql://localhost:5432/reg_auth_db
    user: postgres
    password: postgres

  rabbitmq:
      password: guest
      username: guest
      port: 15672
  redis:
    port: 6379
    host: localhost

Solution

  • I was using wrong port because I had an enterprise edition which had three different ports