Skip to content

Commit 197a581

Browse files
committed
📝 Documentation
1 parent 911ffd9 commit 197a581

File tree

2 files changed

+84
-7
lines changed

2 files changed

+84
-7
lines changed

CONTRIBUTING.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
= Contributing to `spring-boot-embedded-redis`
1+
== Contributing to `spring-boot-embedded-redis`
22

33
`spring-boot-embedded-redis` is released under the Apache 2.0 license.
44
Read on if you would like to contribute!
55

6-
== Code of Conduct
6+
=== Code of Conduct
77

88
This project adheres to the Contributor Covenant xref:CODE_OF_CONDUCT.adoc[code of conduct].
99
By participating, you are expected to uphold this code.
1010

11-
== Using GitHub Issues
11+
=== Using GitHub Issues
1212

1313
This project uses GitHub issues to track bugs and enhancements.
1414
Please check the following before opening an issue:
1515

1616
* your issue is not a duplicate/is not already addressed by another issue
1717
* your issue affects the latest available release
1818

19-
== Code Conventions and Housekeeping
19+
=== Code Conventions and Housekeeping
2020

2121
None of these is essential for a pull request, but they will all help.
2222
They can also be added after the original pull request but before a merge.
@@ -30,7 +30,7 @@ Depending on the change this might entail unit tests, integration tests or both.
3030
This project breaks at less than 100% code coverage, so this is a must.
3131
* Keep your feature branch up-to-date with `main`.
3232

33-
== Building from Source
33+
=== Building from Source
3434

3535
The project can be built from the root directory using:
3636

@@ -39,7 +39,7 @@ The project can be built from the root directory using:
3939
gradle clean build
4040
----
4141

42-
== Releases
42+
=== Releases
4343

4444
Releases are automatically built and published to Maven Central once a tag following the semantic versioning pattern is pushed (i.e. `v1.0.0`).
4545

README.adoc

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,81 @@ link:./LICENSE[image:https://img.shields.io/badge/License-Apache%202.0-orange[Ap
55
image:https://sonarcloud.io/api/project_badges/measure?project=tobias-laa_spring-boot-embedded-redis&metric=alert_status[Quality Gate Status,link=https://sonarcloud.io/summary/new_code?id=tobias-laa_spring-boot-embedded-redis]
66
image:https://sonarcloud.io/api/project_badges/measure?project=tobias-laa_spring-boot-embedded-redis&metric=coverage[Coverage,link=https://sonarcloud.io/summary/new_code?id=tobias-laa_spring-boot-embedded-redis]
77

8-
= Spring Boot `embedded-redis`
8+
= Spring Boot `embedded-redis`
9+
10+
This library provides an easy way to run an embedded Redis server in your Spring Boot integration tests.
11+
It mainly acts as a glue between the https://github.com/codemonstur/embedded-redis[`embedded-redis`] library and Spring Boot.
12+
13+
== Usage
14+
15+
To use the library, add the following dependency to your `pom.xml`:
16+
17+
[source,xml]
18+
----
19+
<dependency>
20+
<groupId>io.github.tobi-laa</groupId>
21+
<artifactId>spring-boot-embedded-redis</artifactId>
22+
<version>1.0.0</version>
23+
<scope>test</scope>
24+
</dependency>
25+
----
26+
27+
You can then declaratively start and stop the embedded Redis server in your integration tests using the `@EmbeddedRedisStandalone` annotation:
28+
29+
[source,java]
30+
----
31+
@EmbeddedRedisStandalone
32+
@SpringBootTest
33+
class MyIntegrationTest {
34+
35+
@Autowired
36+
private RedisTemplate<String, String> redisTemplate;
37+
38+
@Test
39+
void testSomething() {
40+
redisTemplate.opsForValue().set("key", "value");
41+
assertThat(redisTemplate.opsForValue().get("key")).isEqualTo("value");
42+
}
43+
}
44+
----
45+
46+
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.
84+
85+
include::CONTRIBUTING.adoc[]

0 commit comments

Comments
 (0)