Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis value group (replacing the string group) #27871

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions docs/src/main/asciidoc/redis-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ As mentioned above, the API is divided into groups:
- set - `.set(memberType)`
- sorted-set - `.sortedSet(memberType)`
- stream (not available yet)
- string - `.string(valueType)`
- string - `.value(valueType)`
- transactions - `withTransaction`

Each of these methods returns an object that lets you execute the commands related to the group.
Expand Down Expand Up @@ -317,9 +317,9 @@ In this case, `quarkus-jackson` is used.

To store binary data, use `byte[]`.

=== The `string` group
=== The `value` group

The `string` group is used to manipulate https://redis.io/docs/manual/data-types/#strings[Redis Strings].
The `value` group is used to manipulate https://redis.io/docs/manual/data-types/#strings[Redis Strings].
Thus, this group is not limited to Java Strings but can be used for integers (like a counter) or binary content (like images).

==== Caching values
Expand All @@ -332,10 +332,10 @@ The following snippet shows how such a command can be used to store `BusinessObj
@ApplicationScoped
public static class MyRedisCache {

private final StringCommands<String, BusinessObject> commands;
private final ValueCommands<String, BusinessObject> commands;

public MyRedisCache(RedisDataSource ds) {
commands = ds.string(BusinessObject.class);
commands = ds.value(BusinessObject.class);
}

public BusinessObject get(String key) {
Expand Down Expand Up @@ -375,10 +375,10 @@ In this case, we will use `byte[]` as value type:
@ApplicationScoped
public static class MyBinaryRepository {

private final StringCommands<String, byte[]> commands;
private final ValueCommands<String, byte[]> commands;

public MyBinaryRepository(RedisDataSource ds) {
commands = ds.string(byte[].class);
commands = ds.value(byte[].class);
}

public byte[] get(String key) {
Expand Down Expand Up @@ -408,10 +408,10 @@ You can store counters in Redis as demonstrated below:
@ApplicationScoped
public static class MyRedisCounter {

private final StringCommands<String, Long> commands;
private final ValueCommands<String, Long> commands;

public MyRedisCounter(RedisDataSource ds) {
commands = ds.string(Long.class); // <1>
commands = ds.value(Long.class); // <1>
}

public long get(String key) {
Expand Down Expand Up @@ -490,11 +490,11 @@ public static class MySubscriber implements Consumer<Notification> {
@ApplicationScoped
public static class MyCache {

private final StringCommands<String, BusinessObject> commands;
private final ValueCommands<String, BusinessObject> commands;
private final PubSubCommands<Notification> pub;

public MyCache(RedisDataSource ds) {
commands = ds.string(BusinessObject.class);
commands = ds.value(BusinessObject.class);
pub = ds.pubsub(Notification.class);
}

Expand Down
4 changes: 2 additions & 2 deletions docs/src/main/asciidoc/redis.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ public class IncrementService {
// Regular applications will pick one of them.

private ReactiveKeyCommands<String> keyCommands; // <1>
private StringCommands<String, Long> countCommands; // <2>
private ValueCommands<String, Long> countCommands; // <2>

public IncrementService(RedisDataSource ds, ReactiveRedisDataSource reactive) { // <3>
countCommands = ds.string(Long.class); // <4>
countCommands = ds.value(Long.class); // <4>
keyCommands = reactive.key(); // <5>

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,24 @@ public static class MyRedisApp {
ReactiveRedisDataSource myRedisReactive;

public void set(String data) {
reactive.string(String.class, String.class)
reactive.value(String.class, String.class)
.set("foo", data)
.await().indefinitely();
}

public String get() {
return blocking.string(String.class, String.class)
return blocking.value(String.class, String.class)
.get("foo");
}

public void setMyRedis(String data) {
myRedisReactive.string(String.class, String.class)
myRedisReactive.value(String.class, String.class)
.set("foo", data)
.await().indefinitely();
}

public String getMyRedis() {
return myRedisBlocking.string(String.class, String.class)
return myRedisBlocking.value(String.class, String.class)
.get("foo");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.quarkus.redis.client.RedisClientName;
import io.quarkus.redis.client.deployment.RedisTestResource;
import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.redis.datasource.string.StringCommands;
import io.quarkus.redis.datasource.value.ValueCommands;
import io.quarkus.test.QuarkusUnitTest;
import io.quarkus.test.common.QuarkusTestResource;

Expand All @@ -34,8 +34,8 @@ public class DataSourceTest {

@Test
public void testThatTheDatasourceUseDifferentDatabases() {
StringCommands<String, String> r1s = r1.string(String.class);
StringCommands<String, String> r2s = r2.string(String.class);
ValueCommands<String, String> r1s = r1.value(String.class);
ValueCommands<String, String> r2s = r2.value(String.class);

r1s.set("key", "hello");
Assertions.assertThat(r2s.get("key")).isNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import javax.ws.rs.Path;

import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.redis.datasource.string.StringCommands;
import io.quarkus.redis.datasource.value.ValueCommands;

@Path("/inc")
public class IncrementResource {

public static final long INCREMENT = 1;
private final StringCommands<String, Integer> commands;
private final ValueCommands<String, Integer> commands;

public IncrementResource(RedisDataSource ds) {
commands = ds.string(Integer.class);
commands = ds.value(Integer.class);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import io.quarkus.redis.client.deployment.RedisTestResource;
import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.redis.datasource.string.StringCommands;
import io.quarkus.redis.datasource.value.ValueCommands;
import io.quarkus.test.QuarkusUnitTest;
import io.quarkus.test.common.QuarkusTestResource;

Expand Down Expand Up @@ -52,10 +52,10 @@ void binary() {
@ApplicationScoped
public static class MyBinaryRepository {

private final StringCommands<String, byte[]> commands;
private final ValueCommands<String, byte[]> commands;

public MyBinaryRepository(RedisDataSource ds) {
commands = ds.string(byte[].class);
commands = ds.value(byte[].class);
}

public byte[] get(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import io.quarkus.redis.client.deployment.RedisTestResource;
import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.redis.datasource.string.StringCommands;
import io.quarkus.redis.datasource.value.ValueCommands;
import io.quarkus.test.QuarkusUnitTest;
import io.quarkus.test.common.QuarkusTestResource;

Expand Down Expand Up @@ -68,10 +68,10 @@ public BusinessObject(String v) {
@ApplicationScoped
public static class MyRedisCache {

private final StringCommands<String, BusinessObject> commands;
private final ValueCommands<String, BusinessObject> commands;

public MyRedisCache(RedisDataSource ds) {
commands = ds.string(BusinessObject.class);
commands = ds.value(BusinessObject.class);
}

public BusinessObject get(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import io.quarkus.redis.client.deployment.RedisTestResource;
import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.redis.datasource.string.StringCommands;
import io.quarkus.redis.datasource.value.ValueCommands;
import io.quarkus.test.QuarkusUnitTest;
import io.quarkus.test.common.QuarkusTestResource;

Expand Down Expand Up @@ -47,10 +47,10 @@ void counter() {
@ApplicationScoped
public static class MyRedisCounter {

private final StringCommands<String, Long> commands;
private final ValueCommands<String, Long> commands;

public MyRedisCounter(RedisDataSource ds) {
commands = ds.string(Long.class);
commands = ds.value(Long.class);
}

public long get(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.redis.datasource.pubsub.PubSubCommands;
import io.quarkus.redis.datasource.pubsub.ReactivePubSubCommands;
import io.quarkus.redis.datasource.string.StringCommands;
import io.quarkus.redis.datasource.value.ValueCommands;
import io.quarkus.runtime.Startup;
import io.quarkus.test.QuarkusUnitTest;
import io.quarkus.test.common.QuarkusTestResource;
Expand Down Expand Up @@ -115,11 +115,11 @@ public List<Notification> list() {
@ApplicationScoped
public static class MyCache {

private final StringCommands<String, BusinessObject> commands;
private final ValueCommands<String, BusinessObject> commands;
private final PubSubCommands<Notification> pub;

public MyCache(RedisDataSource ds) {
commands = ds.string(BusinessObject.class);
commands = ds.value(BusinessObject.class);
pub = ds.pubsub(Notification.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.quarkus.redis.client.deployment.RedisTestResource;
import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.redis.datasource.pubsub.PubSubCommands;
import io.quarkus.redis.datasource.string.StringCommands;
import io.quarkus.redis.datasource.value.ValueCommands;
import io.quarkus.runtime.Startup;
import io.quarkus.test.QuarkusUnitTest;
import io.quarkus.test.common.QuarkusTestResource;
Expand Down Expand Up @@ -109,11 +109,11 @@ public List<Notification> list() {
@ApplicationScoped
public static class MyCache {

private final StringCommands<String, BusinessObject> commands;
private final ValueCommands<String, BusinessObject> commands;
private final PubSubCommands<Notification> pub;

public MyCache(RedisDataSource ds) {
commands = ds.string(BusinessObject.class);
commands = ds.value(BusinessObject.class);
pub = ds.pubsub(Notification.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.quarkus.redis.datasource.transactions.ReactiveTransactionalRedisDataSource;
import io.quarkus.redis.datasource.transactions.TransactionResult;
import io.quarkus.redis.datasource.transactions.TransactionalRedisDataSource;
import io.quarkus.redis.datasource.value.ReactiveValueCommands;
import io.smallrye.mutiny.Uni;
import io.vertx.mutiny.redis.client.Command;
import io.vertx.mutiny.redis.client.Redis;
Expand Down Expand Up @@ -232,6 +233,34 @@ default <V> ReactiveSortedSetCommands<String, V> sortedSet(Class<V> valueType) {
return sortedSet(String.class, valueType);
}

/**
* Gets the object to execute commands manipulating stored strings.
* <p>
* <strong>NOTE:</strong> Instead of {@code string}, this group is named {@code value} to avoid the confusion with the
* Java String type. Indeed, Redis strings can be strings, numbers, byte arrays...
*
* @param redisKeyType the type of the keys
* @param valueType the type of the value, often String, or the value are encoded/decoded using codecs.
* @param <K> the type of the key
* @param <V> the type of the value
* @return the object to manipulate stored strings.
*/
<K, V> ReactiveValueCommands<K, V> value(Class<K> redisKeyType, Class<V> valueType);

/**
* Gets the object to execute commands manipulating stored strings.
* <p>
* <strong>NOTE:</strong> Instead of {@code string}, this group is named {@code value} to avoid the confusion with the
* Java String type. Indeed, Redis strings can be strings, numbers, byte arrays...
*
* @param valueType the type of the value, often String, or the value are encoded/decoded using codecs.
* @param <V> the type of the value
* @return the object to manipulate stored strings.
*/
default <V> ReactiveValueCommands<String, V> value(Class<V> valueType) {
return value(String.class, valueType);
}

/**
* Gets the object to execute commands manipulating stored strings.
*
Expand All @@ -240,7 +269,9 @@ default <V> ReactiveSortedSetCommands<String, V> sortedSet(Class<V> valueType) {
* @param <K> the type of the key
* @param <V> the type of the value
* @return the object to manipulate stored strings.
* @deprecated Use {@link #value(Class, Class)} instead
*/
@Deprecated
<K, V> ReactiveStringCommands<K, V> string(Class<K> redisKeyType, Class<V> valueType);

/**
Expand All @@ -249,7 +280,9 @@ default <V> ReactiveSortedSetCommands<String, V> sortedSet(Class<V> valueType) {
* @param valueType the type of the value, often String, or the value are encoded/decoded using codecs.
* @param <V> the type of the value
* @return the object to manipulate stored strings.
* @deprecated Use {@link #value(Class)} instead
*/
@Deprecated
default <V> ReactiveStringCommands<String, V> string(Class<V> valueType) {
return string(String.class, valueType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.quarkus.redis.datasource.transactions.OptimisticLockingTransactionResult;
import io.quarkus.redis.datasource.transactions.TransactionResult;
import io.quarkus.redis.datasource.transactions.TransactionalRedisDataSource;
import io.quarkus.redis.datasource.value.ValueCommands;
import io.vertx.mutiny.redis.client.Command;
import io.vertx.mutiny.redis.client.Response;

Expand Down Expand Up @@ -228,6 +229,36 @@ default <V> SortedSetCommands<String, V> sortedSet(Class<V> valueType) {
return sortedSet(String.class, valueType);
}

/**
* Gets the object to execute commands manipulating stored strings.
*
* <p>
* <strong>NOTE:</strong> Instead of {@code string}, this group is named {@code value} to avoid the confusion with the
* Java String type. Indeed, Redis strings can be strings, numbers, byte arrays...
*
* @param redisKeyType the type of the keys
* @param valueType the type of the value, often String, or the value are encoded/decoded using codecs.
* @param <K> the type of the key
* @param <V> the type of the value
* @return the object to manipulate stored strings.
*/
<K, V> ValueCommands<K, V> value(Class<K> redisKeyType, Class<V> valueType);

/**
* Gets the object to execute commands manipulating stored strings.
*
* <p>
* <strong>NOTE:</strong> Instead of {@code string}, this group is named {@code value} to avoid the confusion with the
* Java String type. Indeed, Redis strings can be strings, numbers, byte arrays...
*
* @param valueType the type of the value, often String, or the value are encoded/decoded using codecs.
* @param <V> the type of the value
* @return the object to manipulate stored strings.
*/
default <V> ValueCommands<String, V> value(Class<V> valueType) {
return value(String.class, valueType);
}

/**
* Gets the object to execute commands manipulating stored strings.
*
Expand All @@ -236,7 +267,9 @@ default <V> SortedSetCommands<String, V> sortedSet(Class<V> valueType) {
* @param <K> the type of the key
* @param <V> the type of the value
* @return the object to manipulate stored strings.
* @deprecated Use {@link #value(Class, Class)} instead
*/
@Deprecated
<K, V> StringCommands<K, V> string(Class<K> redisKeyType, Class<V> valueType);

/**
Expand All @@ -245,7 +278,9 @@ default <V> SortedSetCommands<String, V> sortedSet(Class<V> valueType) {
* @param valueType the type of the value, often String, or the value are encoded/decoded using codecs.
* @param <V> the type of the value
* @return the object to manipulate stored strings.
* @deprecated Use {@link #value(Class)} instead
*/
@Deprecated
default <V> StringCommands<String, V> string(Class<V> valueType) {
return string(String.class, valueType);
}
Expand Down
Loading