-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26803 from cescoffier/redis-options-customizer
Add a way to customize the Redis client options
- Loading branch information
Showing
7 changed files
with
145 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...is-client/deployment/src/test/java/io/quarkus/redis/client/deployment/CustomizerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.quarkus.redis.client.deployment; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.eclipse.microprofile.config.spi.ConfigProviderResolver; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.redis.client.RedisClientName; | ||
import io.quarkus.redis.client.RedisOptionsCustomizer; | ||
import io.quarkus.redis.runtime.client.config.RedisConfig; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.vertx.mutiny.redis.client.RedisAPI; | ||
import io.vertx.redis.client.RedisOptions; | ||
|
||
@QuarkusTestResource(RedisTestResource.class) | ||
public class CustomizerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClass(MyCustomizer.class)) | ||
.overrideConfigKey("quarkus.redis.hosts", "redis://wont-work") | ||
.overrideConfigKey("quarkus.redis.my-redis.hosts", "redis://wont-work"); | ||
|
||
@Inject | ||
RedisAPI api; | ||
|
||
@Inject | ||
@RedisClientName("my-redis") | ||
RedisAPI myapi; | ||
|
||
@Test | ||
public void testCustomization() { | ||
String key = UUID.randomUUID().toString(); | ||
api.setAndAwait(List.of(key, "test-" + key)); | ||
String v = myapi.getAndAwait(key).toString(); | ||
Assertions.assertThat(v).isEqualTo("test-" + key); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class MyCustomizer implements RedisOptionsCustomizer { | ||
|
||
@Override | ||
public void customize(String clientName, RedisOptions options) { | ||
String v = ConfigProviderResolver.instance().getConfig().getValue("quarkus.redis.tr", String.class); | ||
if (clientName.equalsIgnoreCase("my-redis") | ||
|| clientName.equalsIgnoreCase(RedisConfig.DEFAULT_CLIENT_NAME)) { | ||
options.setEndpoints(List.of(v)); | ||
} else { | ||
throw new IllegalStateException("Unknown client name: " + clientName); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ns/redis-client/runtime/src/main/java/io/quarkus/redis/client/RedisOptionsCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.redis.client; | ||
|
||
import io.vertx.redis.client.RedisOptions; | ||
|
||
/** | ||
* Beans exposing the {@code RedisClientOptionsCustomizer} interface has the possibility to extend/modify the | ||
* {@link io.vertx.redis.client.RedisOptions} before they are used to create the {@code RedisClient} or | ||
* {@code RedisDataSource}. | ||
*/ | ||
public interface RedisOptionsCustomizer { | ||
|
||
/** | ||
* Allows customizing the options for the client named {@code clientName}. | ||
* The passed {@code options} must be modified <em>in-place</em>. | ||
* | ||
* @param clientName the client name, {@link io.quarkus.redis.runtime.client.config.RedisConfig#DEFAULT_CLIENT_NAME} | ||
* for the default client. | ||
* @param options the options. | ||
*/ | ||
void customize(String clientName, RedisOptions options); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters