An open API service indexing awesome lists of open source software.

https://github.com/redis-field-engineering/testcontainers-redis

Testcontainers module for Redis
https://github.com/redis-field-engineering/testcontainers-redis

Last synced: 3 months ago
JSON representation

Testcontainers module for Redis

Awesome Lists containing this project

README

        

= Testcontainers Redis
:linkattrs:
:project-owner: redis-field-engineering
:project-name: testcontainers-redis
:project-group: com.redis
:project-version: 2.2.4

image:https://github.com/{project-owner}/{project-name}/actions/workflows/early-access.yml/badge.svg["Build Status",link="https://github.com/{project-owner}/{project-name}/actions"]
image:https://img.shields.io/maven-central/v/{project-group}/{project-name}[Download,link="https://search.maven.org/#search|ga|1|{project-name}"]
image:https://img.shields.io/github/license/{project-owner}/{project-name}["License",link="https://github.com/{project-owner}/{project-name}"]

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

== Getting Started

=== Gradle

[source,groovy,subs="+attributes"]
----
dependencies {
testImplementation "{project-group}:{project-name}:{project-version}"
}
----

=== Maven

[source,xml,subs="+attributes"]
----

{project-group}
{project-name}
{project-version}
test

----

== Usage

=== Redis Example

[source,java]
----
@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();
RedisClient client = RedisClient.create(redisURI);
try (StatefulRedisConnection connection = client.connect()) {
RedisCommands commands = connection.sync();
Assertions.assertEquals("PONG", commands.ping());
}
}
}
----

=== Redis Stack Example

[source,java]
----
@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();
RedisModulesClient client = RedisModulesClient.create(redisURI);
try (StatefulRedisModulesConnection connection = client.connect()) {
RedisModulesCommands commands = connection.sync();
commands.ftCreate("myIndex", Field.tag("myField").build());
IndexInfo indexInfo = RedisModulesUtils.indexInfo(commands.ftInfo("myIndex"));
Assertions.assertEquals(1, indexInfo.getFields().size());
Assertions.assertEquals("myField", indexInfo.getFields().get(0).getName());
}
}
}
----