You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This will start an embedded Redis server before the Spring context corresponding to the test class is loaded for the first time and stop it after the context is closed.
47
+
The necessary Spring Data Redis properties are automatically set.
48
+
49
+
You can also use the `@EmbeddedRedisShardedCluster` annotation to start an embedded Redis cluster:
50
+
51
+
[source,java]
52
+
----
53
+
@EmbeddedRedisShardedCluster
54
+
@SpringBootTest
55
+
class MyIntegrationTest {
56
+
// ...
57
+
}
58
+
----
59
+
60
+
There is also the possibility to start the embedded Redis server in high availability mode with replicas and sentinels using the `@EmbeddedRedisHighAvailability` annotation:
61
+
62
+
[source,java]
63
+
----
64
+
@EmbeddedRedisHighAvailability
65
+
@SpringBootTest
66
+
class MyIntegrationTest {
67
+
// ...
68
+
}
69
+
----
70
+
71
+
By default, data stored in the embedded Redis server is flushed after each test method.
72
+
You can disable this behavior by annotating your test class with `@RedisFlushAll(mode = Mode.AFTER_CLASS)` or `@RedisFlushAll(mode = Mode.NEVER)`.
73
+
74
+
The embedded Redis instances will be started on free ports found starting at the default ports (that is, `6379` or `26379` for sentinels) and be bound to `localhost` by default.
75
+
76
+
Using an embedded Redis does not break Spring's context caching.
77
+
If you have some integration tests running without an embedded Redis and some with, you will however end up with two different contexts as the properties of the Spring context are modified.
78
+
79
+
== Acknowledgements
80
+
81
+
This library is heavily inspired by the awesome https://github.com/maciejwalkowiak/wiremock-spring-boot[WireMock Spring Boot] library.
82
+
83
+
Furthermore, this library would of course not exist without the https://github.com/codemonstur/embedded-redis[`embedded-redis`] library.
0 commit comments