# Step 6: Adding Redis

The simplest way to provide a Redis instance for your tests is to use `GenericContainer` with a Redis Docker image: <https://www.testcontainers.org/usage/generic_containers.html> The integration between the tests code and Testcontainers is straightforward.

## Rules? No thanks!

Testcontainers comes with first class support for JUnit, but in our app we want to have a single Redis instance shared between **all** tests. Luckily, there are the `.start()`/`.stop()` methods of `GenericContainer` to start or stop it manually.

Just add the following code to your `AbstractIntegrationTest` with the following code:

```java
static final GenericContainer redis = new GenericContainer("redis:6-alpine")
                                            .withExposedPorts(6379);

@DynamicPropertySource
public static void configureRedis(DynamicPropertyRegistry registry) {
  redis.start();
  registry.add("spring.redis.host", redis::getHost);
  registry.add("spring.redis.port", redis::getFirstMappedPort);
}
```

Simple and beautiful, huh?

Run the tests, now they should all pass.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://testcontainers.gitbook.io/workshop/step-6-adding-redis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
