@@ -35,8 +35,48 @@ dependencies {
3535
3636== Usage
3737
38- Redis::
39- https://github.com/redis-developer/testcontainers-redis/tree/master/subprojects/testcontainers-redis-junit/src/test/java/com/redis/testcontainers/junit/RedisTests.java[RedisTests.java]
38+ .Redis Example
39+ [source,java]
40+ ----
41+ @Testcontainers
42+ public class RedisExampleTest {
43+
44+ @Container
45+ private static RedisContainer redisContainer = new RedisContainer(
46+ RedisContainer.DEFAULT_IMAGE_NAME.withTag(RedisContainer.DEFAULT_TAG));
47+
48+ @Test
49+ void testSomethingUsingLettuce() {
50+ // Retrieve the Redis URI from the container
51+ String redisURI = redisContainer.getRedisURI();
52+ RedisClient client = RedisClient.create(redisURI);
53+ try (StatefulRedisConnection<String, String> connection = client.connect()) {
54+ RedisCommands<String, String> commands = connection.sync();
55+ Assertions.assertEquals("PONG", commands.ping());
56+ }
57+ }
58+ }
59+ ----
4060
41- Redis Modules::
42- https://github.com/redis-developer/testcontainers-redis/tree/master/subprojects/testcontainers-redis-junit/src/test/java/com/redis/testcontainers/junit/RedisModulesTests.java[RedisModulesTests.java]
61+ .Redis Stack Example
62+ [source,java]
63+ ----
64+ @Testcontainers
65+ class RedisStackExampleTest {
66+
67+ @Container
68+ private static RedisStackContainer redisContainer = new RedisStackContainer(
69+ RedisStackContainer.DEFAULT_IMAGE_NAME.withTag(RedisStackContainer.DEFAULT_TAG));
70+
71+ @Test
72+ void testSomethingUsingLettuceMod() {
73+ // Retrieve the Redis URI from the container
74+ String redisURI = redisContainer.getRedisURI();
75+ RedisModulesClient client = RedisModulesClient.create(redisURI);
76+ try (StatefulRedisModulesConnection<String, String> connection = client.connect()) {
77+ RedisModulesCommands<String, String> commands = connection.sync();
78+ Assertions.assertEquals("PONG", commands.ping());
79+ }
80+ }
81+ }
82+ ----
0 commit comments