@@ -26,9 +26,6 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Value
|
||||
@RequiredArgsConstructor
|
||||
@JsonTypeInfo(use = Id.CLASS, property = "_type")
|
||||
public class EmailAddress {
|
||||
final String address;
|
||||
public record EmailAddress(String address) {
|
||||
}
|
||||
|
||||
@@ -51,11 +51,11 @@ public class RedisTestConfiguration {
|
||||
public ReactiveRedisTemplate<String, Person> reactiveJsonPersonRedisTemplate(
|
||||
ReactiveRedisConnectionFactory connectionFactory) {
|
||||
|
||||
Jackson2JsonRedisSerializer<Person> serializer = new Jackson2JsonRedisSerializer<>(Person.class);
|
||||
var serializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
|
||||
RedisSerializationContextBuilder<String, Person> builder = RedisSerializationContext
|
||||
.newSerializationContext(new StringRedisSerializer());
|
||||
|
||||
RedisSerializationContext<String, Person> serializationContext = builder.value(serializer).build();
|
||||
var serializationContext = builder.value(serializer).build();
|
||||
|
||||
return new ReactiveRedisTemplate<>(connectionFactory, serializationContext);
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class RedisTestConfiguration {
|
||||
RedisSerializationContextBuilder<String, Object> builder = RedisSerializationContext
|
||||
.newSerializationContext(new StringRedisSerializer());
|
||||
|
||||
RedisSerializationContext<String, Object> serializationContext = builder
|
||||
var serializationContext = builder
|
||||
.value(new GenericJackson2JsonRedisSerializer("_type")).build();
|
||||
|
||||
return new ReactiveRedisTemplate<>(connectionFactory, serializationContext);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class KeyCommandsTests {
|
||||
|
||||
generateRandomKeys(50);
|
||||
|
||||
Mono<Long> keyCount = connection.keyCommands() //
|
||||
var keyCount = connection.keyCommands() //
|
||||
.keys(ByteBuffer.wrap(serializer.serialize(KEY_PATTERN))) //
|
||||
.flatMapMany(Flux::fromIterable) //
|
||||
.doOnNext(byteBuffer -> System.out.println(toString(byteBuffer))) //
|
||||
@@ -93,12 +93,12 @@ public class KeyCommandsTests {
|
||||
@Test
|
||||
public void storeToListAndPop() {
|
||||
|
||||
Mono<PopResult> popResult = connection.listCommands()
|
||||
var popResult = connection.listCommands()
|
||||
.brPop(Collections.singletonList(ByteBuffer.wrap("list".getBytes())), Duration.ofSeconds(5));
|
||||
|
||||
Mono<Long> llen = connection.listCommands().lLen(ByteBuffer.wrap("list".getBytes()));
|
||||
var llen = connection.listCommands().lLen(ByteBuffer.wrap("list".getBytes()));
|
||||
|
||||
Mono<Long> popAndLlen = connection.listCommands() //
|
||||
var popAndLlen = connection.listCommands() //
|
||||
.rPush(ByteBuffer.wrap("list".getBytes()), Collections.singletonList(ByteBuffer.wrap("item".getBytes())))
|
||||
.flatMap(l -> popResult) //
|
||||
.doOnNext(result -> System.out.println(toString(result.getValue()))) //
|
||||
@@ -110,9 +110,9 @@ public class KeyCommandsTests {
|
||||
|
||||
private void generateRandomKeys(int nrKeys) {
|
||||
|
||||
Flux<String> keyFlux = Flux.range(0, nrKeys).map(i -> (PREFIX + "-" + i));
|
||||
var keyFlux = Flux.range(0, nrKeys).map(i -> (PREFIX + "-" + i));
|
||||
|
||||
Flux<SetCommand> generator = keyFlux.map(String::getBytes).map(ByteBuffer::wrap) //
|
||||
var generator = keyFlux.map(String::getBytes).map(ByteBuffer::wrap) //
|
||||
.map(key -> SetCommand.set(key) //
|
||||
.value(ByteBuffer.wrap(UUID.randomUUID().toString().getBytes())));
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class JacksonJsonTests {
|
||||
.expectNext(true) //
|
||||
.verifyComplete();
|
||||
|
||||
Flux<String> get = typedOperations.execute(conn -> conn.stringCommands().get(ByteBuffer.wrap("homer".getBytes()))) //
|
||||
var get = typedOperations.execute(conn -> conn.stringCommands().get(ByteBuffer.wrap("homer".getBytes()))) //
|
||||
.map(ByteUtils::getBytes) //
|
||||
.map(String::new);
|
||||
|
||||
@@ -93,7 +93,7 @@ public class JacksonJsonTests {
|
||||
.expectNext(true) //
|
||||
.verifyComplete();
|
||||
|
||||
Flux<String> get = genericOperations.execute(conn -> conn.stringCommands().get(ByteBuffer.wrap("homer".getBytes()))) //
|
||||
var get = genericOperations.execute(conn -> conn.stringCommands().get(ByteBuffer.wrap("homer".getBytes()))) //
|
||||
.map(ByteUtils::getBytes) //
|
||||
.map(String::new);
|
||||
|
||||
@@ -121,7 +121,7 @@ public class JacksonJsonTests {
|
||||
.expectNext(true) //
|
||||
.verifyComplete();
|
||||
|
||||
Flux<String> get = genericOperations.execute(conn -> conn.stringCommands().get(ByteBuffer.wrap("mail".getBytes()))) //
|
||||
var get = genericOperations.execute(conn -> conn.stringCommands().get(ByteBuffer.wrap("mail".getBytes()))) //
|
||||
.map(ByteUtils::getBytes) //
|
||||
.map(String::new);
|
||||
|
||||
|
||||
@@ -60,11 +60,11 @@ public class ListOperationsTests {
|
||||
@Test
|
||||
public void shouldPollAndPopulateQueue() {
|
||||
|
||||
String queue = "foo";
|
||||
var queue = "foo";
|
||||
|
||||
ReactiveListOperations<String, String> listOperations = operations.opsForList();
|
||||
var listOperations = operations.opsForList();
|
||||
|
||||
Mono<String> blpop = listOperations //
|
||||
var blpop = listOperations //
|
||||
.leftPop(queue, Duration.ofSeconds(30)) //
|
||||
.log("example.springdata.redis", Level.INFO);
|
||||
|
||||
|
||||
@@ -61,11 +61,11 @@ public class ValueOperationsTests {
|
||||
@Test
|
||||
public void shouldCacheValue() {
|
||||
|
||||
String cacheKey = "foo";
|
||||
var cacheKey = "foo";
|
||||
|
||||
ReactiveValueOperations<String, String> valueOperations = operations.opsForValue();
|
||||
var valueOperations = operations.opsForValue();
|
||||
|
||||
Mono<String> cachedMono = valueOperations.get(cacheKey) //
|
||||
var cachedMono = valueOperations.get(cacheKey) //
|
||||
.switchIfEmpty(cacheValue().flatMap(it -> {
|
||||
|
||||
return valueOperations.set(cacheKey, it, Duration.ofSeconds(60)).then(Mono.just(it));
|
||||
@@ -80,7 +80,7 @@ public class ValueOperationsTests {
|
||||
|
||||
log.info("Subsequent access (use cached value)");
|
||||
|
||||
Duration duration = StepVerifier.create(cachedMono) //
|
||||
var duration = StepVerifier.create(cachedMono) //
|
||||
.expectNext("Hello, World!") //
|
||||
.verifyComplete();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user