-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(redis): introduce factory methods to create clients dynamically
Closes #13887
- Loading branch information
Showing
18 changed files
with
271 additions
and
263 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
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
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
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
37 changes: 37 additions & 0 deletions
37
...dis-client/runtime/src/test/java/io/quarkus/redis/client/runtime/RedisClientUtilTest.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,37 @@ | ||
package io.quarkus.redis.client.runtime; | ||
|
||
import static io.quarkus.redis.client.runtime.RedisClientUtil.DEFAULT_CLIENT; | ||
import static io.quarkus.redis.client.runtime.RedisClientUtil.getConfiguration; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.util.HashMap; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.redis.client.runtime.RedisConfig.RedisConfiguration; | ||
|
||
class RedisClientUtilTest { | ||
|
||
@Test | ||
void testGetConfiguration() { | ||
RedisConfig config = new RedisConfig(); | ||
config.defaultClient = new RedisConfiguration(); | ||
config.additionalRedisClients = new HashMap<>(); | ||
RedisConfiguration namedConfiguration = new RedisConfiguration(); | ||
config.additionalRedisClients.put("some-configuration", namedConfiguration); | ||
|
||
// get default client configuration | ||
RedisConfiguration configuration = getConfiguration(config, DEFAULT_CLIENT); | ||
assertThat(configuration).isEqualTo(config.defaultClient); | ||
|
||
// get named client configuration | ||
configuration = getConfiguration(config, "some-configuration"); | ||
assertThat(configuration).isEqualTo(namedConfiguration); | ||
|
||
// throw error for non-existing named client | ||
assertThatThrownBy(() -> { | ||
getConfiguration(config, "non-existing"); | ||
}).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...edis-client/src/main/java/io/quarkus/redis/it/RedisWithDynamicClientCreationResource.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,50 @@ | ||
package io.quarkus.redis.it; | ||
|
||
import java.util.Arrays; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
|
||
import io.quarkus.redis.client.RedisClient; | ||
import io.quarkus.redis.client.reactive.ReactiveRedisClient; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.redis.client.Response; | ||
|
||
@Path("/quarkus-redis-dynamic-client-creation") | ||
@ApplicationScoped | ||
public class RedisWithDynamicClientCreationResource { | ||
// synchronous | ||
@GET | ||
@Path("/sync/{key}") | ||
public String getSync(@PathParam("key") String key) { | ||
Response response = RedisClient.createClient("dynamic").get(key); | ||
return response == null ? null : response.toString(); | ||
} | ||
|
||
@POST | ||
@Path("/sync/{key}") | ||
public void setSync(@PathParam("key") String key, String value) { | ||
RedisClient.createClient("dynamic").set(Arrays.asList(key, value)); | ||
} | ||
|
||
// reactive | ||
@GET | ||
@Path("/reactive/{key}") | ||
public Uni<String> getReactive(@PathParam("key") String key) { | ||
return ReactiveRedisClient.createClient("dynamic") | ||
.get(key) | ||
.map(response -> response == null ? null : response.toString()); | ||
} | ||
|
||
@POST | ||
@Path("/reactive/{key}") | ||
public Uni<Void> setReactive(@PathParam("key") String key, String value) { | ||
return ReactiveRedisClient.createClient("dynamic") | ||
.set(Arrays.asList(key, value)) | ||
.map(response -> null); | ||
} | ||
|
||
} |
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
Oops, something went wrong.