use of org.springframework.data.redis.core.ReactiveStringRedisTemplate in project redisson by redisson.
the class RedissonSubscribeReactiveTest method testPubSub.
@Test
public void testPubSub() {
RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
AtomicLong counter = new AtomicLong();
ReactiveStringRedisTemplate template = new ReactiveStringRedisTemplate(factory);
template.listenTo(ChannelTopic.of("test")).flatMap(message -> {
counter.incrementAndGet();
return Mono.empty();
}).subscribe();
for (int i = 0; i < 40; i++) {
ReactiveRedisConnection connection = factory.getReactiveConnection();
connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();
}
Awaitility.await().atMost(Duration.ONE_SECOND).untilAsserted(() -> {
assertThat(counter.get()).isEqualTo(40);
});
}
use of org.springframework.data.redis.core.ReactiveStringRedisTemplate in project redisson by redisson.
the class RedissonReactiveTest method testGetSet.
@Test
public void testGetSet() {
RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
ReactiveStringRedisTemplate template = new ReactiveStringRedisTemplate(factory);
Assertions.assertThat(template.opsForValue().get("123").block()).isNull();
template.opsForValue().set("123", "444").block();
Assertions.assertThat(template.opsForValue().get("123").block()).isEqualTo("444");
}
use of org.springframework.data.redis.core.ReactiveStringRedisTemplate in project redisson by redisson.
the class RedissonSubscribeReactiveTest method testTemplate.
@Test
public void testTemplate() {
RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
AtomicLong counter = new AtomicLong();
ReactiveStringRedisTemplate template = new ReactiveStringRedisTemplate(factory);
template.listenTo(ChannelTopic.of("test")).flatMap(message -> {
counter.incrementAndGet();
return Mono.empty();
}).subscribe();
template.listenTo(ChannelTopic.of("test2")).flatMap(message -> {
counter.incrementAndGet();
return Mono.empty();
}).subscribe();
ReactiveRedisConnection connection = factory.getReactiveConnection();
connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();
Awaitility.await().atMost(Duration.ONE_SECOND).until(() -> counter.get() == 1);
}
Aggregations