Skip to content

Embedded Redis for Spring Boot

I run my Integration Test cases with Spring Boot with the help of my local Redis server on my machine.

But I want an embedded Redis server which is not dependent on any server and can run on any environment, like the H2 in-memory database. How can I do it?

@SpringApplicationConfiguration(classes = Application.class) 
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class MasterIntegrationTest {



You can use an embedded Redis like

  1. Add the dependency to your pom.xml
  2. Adjust the properties for your integration test to point to your embedded redis, for example :

        host: localhost
        port: 6379
  3. Instanciate the embedded redis server in a component that is defined in your tests only :

    public class EmbededRedis {
        private int redisPort;
        private RedisServer redisServer;
        public void startRedis() throws IOException {
            redisServer = new RedisServer(redisPort);
        public void stopRedis() {