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
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/redis-reference.adoc
+65Lines changed: 65 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,6 +138,70 @@ public class RedisExample {
138
138
139
139
TIP: You can omit the `@Inject` annotation when using `@RedisClientName`.
140
140
141
+
=== Activate or deactivate Redis Clients
142
+
143
+
When a Redis Clients is configured at build time, and its URL is set at runtime, it is active by default. Quarkus
144
+
starts the corresponding Redis Client when the application starts.
145
+
146
+
To deactivate a Redis Client at runtime, either:
147
+
148
+
* Do not set `quarkus.redis[.optional name].hosts` or `quarkus.redis[.optional name].hosts-provider-name`.
149
+
* Set `quarkus.redis[.optional name].active` to `false`.
150
+
151
+
If a Redis Client is not active:
152
+
153
+
* The Redis Client does not attempt to connect to Redis during application startup.
154
+
* The Redis Client does not contribute a <<redis-health-check,health check>>.
155
+
* Static CDI injection points involving the Redis Client, such as `@Inject ReactiveRedisDataSource redis` or `@Inject RedisDataSource redis`, cause application startup to fail.
156
+
* Dynamic retrieval of the Redis Client, such as through `CDI.getBeanContainer()`, `Arc.instance()`, or an injected `Instance<ReactiveRedisDataSource>`, causes an exception to be thrown.
157
+
* Other Quarkus extensions that consume the Redis Client may cause application startup to fail.
158
+
159
+
This feature is especially useful when the application must dynamically select a Redis Client from a predefined set at
160
+
runtime.
161
+
162
+
.An example of configuring multiple Redis Clients for runtime selection:
163
+
164
+
[source,properties]
165
+
----
166
+
quarkus.redis.one.active=false
167
+
quarkus.redis.one.hosts=redis://localhost:64251
168
+
169
+
quarkus.redis.two.active=false
170
+
quarkus.redis.two.hosts=redis://localhost:64251
171
+
----
172
+
173
+
[source,java]
174
+
----
175
+
import io.quarkus.arc.InjectableInstance;
176
+
177
+
@ApplicationScoped
178
+
public class MyConsumer {
179
+
@Inject
180
+
@RedisClientName("one")
181
+
InjectableInstance<ReactiveRedisDataSource> one;
182
+
@Inject
183
+
@RedisClientName("two")
184
+
InjectableInstance<ReactiveRedisDataSource> two;
185
+
186
+
public void doSomething() {
187
+
ReactiveRedisDataSource redis = one.getActive();
188
+
// ...
189
+
}
190
+
}
191
+
----
192
+
193
+
Setting `quarkus.redis.one.active=true` xref:config-reference.adoc#configuration-sources[at runtime] makes only the
194
+
Redis Client `one` available.
195
+
Setting `quarkus.redis.two.active=true` at runtime makes only the Redis Client `two` available.
196
+
197
+
[IMPORTANT]
198
+
====
199
+
A Redis Client (either default or named) must always be discoverable at build-time to be considered for runtime
200
+
injection. This can be done by injecting the Redis Client name with `@RedisClientName`. If the Redis Client name may be
201
+
active or inactive, it needs to use the wrapper `InjectableInstance<>`, or else Quarkus will throw an exception at
202
+
startup time if the Redis Client is inactive. Alternatively, Redis Clients may also be discovered via configuration.
203
+
====
204
+
141
205
== Connect to the Redis server
142
206
143
207
The Redis extension can operate in 4 distinct modes:
@@ -1014,6 +1078,7 @@ See xref:redis-dev-services.adoc[Redis Dev Service].
1014
1078
1015
1079
== Configure Redis observability
1016
1080
1081
+
[[redis-health-check]]
1017
1082
=== Enable the health checks
1018
1083
1019
1084
If you are using the `quarkus-smallrye-health` extension, `quarkus-redis` will automatically add a readiness health check to validate the connection to the Redis server.
Copy file name to clipboardExpand all lines: extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/DevServicesRedisProcessor.java
Copy file name to clipboardExpand all lines: extensions/redis-client/deployment/src/main/java/io/quarkus/redis/deployment/client/RedisClientBuildTimeConfig.java
0 commit comments