Skip to content

Commit 9196d18

Browse files
authored
Merge pull request #42540 from Ladicek/redis-cache-unordered
Redis cache: make blocking executions unordered
2 parents 698f5bf + 1fd2a9a commit 9196d18

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.quarkus.cache.redis.deployment;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.List;
6+
7+
import jakarta.enterprise.context.ApplicationScoped;
8+
import jakarta.inject.Inject;
9+
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.extension.RegisterExtension;
12+
13+
import io.quarkus.arc.Arc;
14+
import io.quarkus.cache.CacheResult;
15+
import io.quarkus.redis.datasource.RedisDataSource;
16+
import io.quarkus.test.QuarkusUnitTest;
17+
18+
public class ChainedRedisCacheTest {
19+
@RegisterExtension
20+
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
21+
.withApplicationRoot(jar -> jar.addClasses(ChainedCachedService.class, TestUtil.class));
22+
23+
@Inject
24+
ChainedCachedService chainedCachedService;
25+
26+
@Test
27+
public void test() {
28+
RedisDataSource redisDataSource = Arc.container().select(RedisDataSource.class).get();
29+
List<String> allKeysAtStart = TestUtil.allRedisKeys(redisDataSource);
30+
31+
assertEquals("fubar:42", chainedCachedService.cache1("fubar"));
32+
33+
List<String> allKeysAtEnd = TestUtil.allRedisKeys(redisDataSource);
34+
assertEquals(allKeysAtStart.size() + 2, allKeysAtEnd.size());
35+
}
36+
37+
@ApplicationScoped
38+
public static class ChainedCachedService {
39+
@CacheResult(cacheName = "cache1")
40+
public String cache1(String key) {
41+
return key + ":" + cache2(42);
42+
}
43+
44+
@CacheResult(cacheName = "cache2")
45+
public int cache2(int value) {
46+
return value;
47+
}
48+
}
49+
}

extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private <K, V> Uni<V> computeValue(K key, Function<K, V> valueLoader, boolean is
141141
public V get() {
142142
return valueLoader.apply(key);
143143
}
144-
}).runSubscriptionOn(MutinyHelper.blockingExecutor(vertx.getDelegate()));
144+
}).runSubscriptionOn(MutinyHelper.blockingExecutor(vertx.getDelegate(), false));
145145
} else {
146146
return Uni.createFrom().item(valueLoader.apply(key));
147147
}
@@ -205,8 +205,8 @@ public Uni<?> apply(V value) {
205205
result = set(connection, encodedKey, encodedValue).replaceWith(value);
206206
}
207207
if (isWorkerThread) {
208-
return result
209-
.runSubscriptionOn(MutinyHelper.blockingExecutor(vertx.getDelegate()));
208+
return result.runSubscriptionOn(
209+
MutinyHelper.blockingExecutor(vertx.getDelegate(), false));
210210
}
211211
return result;
212212
}

0 commit comments

Comments
 (0)