Skip to content

About

Testcontainers module for Redis

Resources

Stars

49 stars

Watchers

6 watching

Forks

Repository files navigation

Testcontainers Redis

Build Status Download License

Testcontainers Redis is an extension of Testcontainers that supports Redis (Standalone and Cluster), Redis Modules, and Redis Enterprise containers.

Building and Compatibility

The 3.x development line uses Spring Boot 4.1 dependency management, Testcontainers 2, and JUnit 6. Java 17 remains the minimum supported version. The libraries are regular JARs; the Spring Boot BOM supplies dependency versions without applying Spring Boot application packaging.

Build with the Gradle wrapper and a JDK 17 or newer:

./gradlew build aggregateTestReports aggregateJacocoReport
./gradlew publish

Docker must be running for Redis, Redis Stack, and Memcached integration tests. Redis Enterprise container tests run on Linux. Tests against an external Redis Enterprise installation require the REDIS_ENTERPRISE_HOST environment variable. The publish task only stages artifacts under build/repos/local/release; it does not upload them to Maven Central.

Dependency versions are maintained in gradle/libs.versions.toml. Dependabot checks the catalog, Gradle wrapper, and this repository’s GitHub Actions weekly. The shared release workflows are maintained in redis-field-engineering/redis-github-workflows.

For development snapshots, build and publish to Maven Local with ./gradlew publishToMavenLocal to try changes before a release.

Getting Started

Gradle

dependencies {
    testImplementation "com.redis:testcontainers-redis:3.0.0"
}

Maven

<dependency>
    <groupId>com.redis</groupId>
    <artifactId>testcontainers-redis</artifactId>
    <version>3.0.0</version>
    <scope>test</scope>
</dependency>

Usage

Redis Example

@Testcontainers
class RedisExampleTest {

    @Container
    private static RedisContainer container = new RedisContainer(
            RedisContainer.DEFAULT_IMAGE_NAME.withTag(RedisContainer.DEFAULT_TAG));

    @Test
    void testSomethingUsingLettuce() {
        // Retrieve the Redis URI from the container
        String redisURI = container.getRedisURI();
        try (RedisClient client = RedisClient.create(redisURI);
                StatefulRedisConnection<String, String> connection = client.connect()) {
            RedisCommands<String, String> commands = connection.sync();
            Assertions.assertEquals("PONG", commands.ping());
        }
    }
}

Redis Stack Example

@Testcontainers
class RedisStackExampleTest {

    @Container
    private static RedisStackContainer container = new RedisStackContainer(
            RedisStackContainer.DEFAULT_IMAGE_NAME.withTag(RedisStackContainer.DEFAULT_TAG));

    @Test
    void testSomethingUsingLettuceMod() {
        // Retrieve the Redis URI from the container
        String redisURI = container.getRedisURI();
        try (RedisModulesClient client = RedisModulesClient.create(redisURI);
                StatefulRedisModulesConnection<String, String> connection = client.connect()) {
            RedisModulesCommands<String, String> commands = connection.sync();
            commands.ftCreate("myIndex", List.of(TagFieldArgs.<String>builder().name("myField").build()));
            IndexInfo indexInfo = IndexInfo.parse(commands.ftInfo("myIndex"));
            Assertions.assertEquals(1, indexInfo.getFields().size());
            Assertions.assertEquals("myField", indexInfo.getFields().get(0).getName());
        }
    }
}

About

Testcontainers module for Redis

Resources

Stars

49 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages