kstyrc / embedded-redis

Redis embedded server for Java integration testing
854 stars 371 forks source link

Connection refused #21

Closed kgunnerud closed 9 years ago

kgunnerud commented 9 years ago

I'm getting Connection Refused when using it with Spring Session. If I start Redis myself, it works fine, but embedded does not work.

Code:

@Configuration
public class EmbeddedRedisConfig {

@Bean
public static RedisServerBean redisServer() {
    return new RedisServerBean();
}

static class RedisServerBean implements InitializingBean, DisposableBean, BeanDefinitionRegistryPostProcessor {
    private RedisServer redisServer;

    public void afterPropertiesSet() throws Exception {
        redisServer = RedisServer.builder()
                .port(Protocol.DEFAULT_PORT)
                .setting("notify-keyspace-events Elg")
                .build();
        redisServer.start();
    }

    public void destroy() throws Exception {
        if(redisServer != null) {
            redisServer.stop();
        }
    }

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {}

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {}
}

For some reason, I have to specify the .setting("notify-keyspace-events Elg"), else I get a: Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR Unsupported CONFIG parameter: notify-keyspace-events

But that's not the problem, when i add that parameter, the next problem is that it wont connect. I just get this: Caused by: java.net.ConnectException: Connection refused: connect

It's like it doesnt start when I add the setting("notify-keyspace-events Elg"), since usually I get the "Firewall warning" asking me if I want redis to gain access to the network. But that does not come when I specify the setting("notify-keyspace-events Elg").

kstyrc commented 9 years ago

Hmm, strange. Do you use embedded-redis 0.3? Or some custom build from master branch? The thing is that when you use setting("<some-setting">"), underneath RedisServer writes all your settings into tmp file and gives that config file to redis binary. You can easily debug your problem the following way: 1) setup a breakpoint after RedisServer.start() 2) verify that redis is running: ps aux | grep redis and ports are there netstat -tulpn 3) verify redis config file content (in debugger inspect RedisServer.redisConf member)

But to be honest, the problem is with your Jedis client most probably. Embedded-redis-0.3 uses redis binary 2.6, which may be not correct to access using client for redis 2.8? Check that