Merge pull request #6368 from seakider/fix_contains

Fixed - The Bloom filter encounters an error if a contains() request …
pull/6370/head
Nikita Koksharov 1 month ago committed by GitHub
commit 5871809606
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -171,12 +171,20 @@ public class RedissonBloomFilter<T> extends RedissonExpirable implements RBloomF
@Override
public RFuture<Long> containsAsync(Collection<T> objects) {
CompletionStage<Void> future = CompletableFuture.completedFuture(null);
CompletionStage<Long> f = CompletableFuture.completedFuture(null);
if (size == 0) {
future = readConfigAsync();
f = readConfigAsync().handle((r, e) -> {
if (e instanceof IllegalArgumentException) {
return 0L;
}
return null;
});
}
CompletionStage<Long> f = future.thenCompose(r -> {
f = f.thenCompose(r -> {
if (r != null) {
return CompletableFuture.completedFuture(r);
}
List<Long> allIndexes = index(objects);
List<Object> params = new ArrayList<>();
@ -188,7 +196,9 @@ public class RedissonBloomFilter<T> extends RedissonExpirable implements RBloomF
return commandExecutor.evalWriteAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_LONG,
"local size = redis.call('hget', KEYS[1], 'size');" +
"local hashIterations = redis.call('hget', KEYS[1], 'hashIterations');" +
"assert(size == ARGV[1] and hashIterations == ARGV[2], 'Bloom filter config has been changed')" +
"if size ~= ARGV[1] or hashIterations ~= ARGV[2] then " +
"return 0;" +
"end;" +
"local k = 0;" +
"local c = 0;" +

@ -110,14 +110,6 @@ public class RedissonBloomFilterTest extends RedisDockerTest {
assertThat(redisson.getKeys().count()).isZero();
}
@Test
public void testNotInitializedOnContains() {
Assertions.assertThrows(RedisException.class, () -> {
RBloomFilter<String> filter = redisson.getBloomFilter("filter");
filter.contains("32");
});
}
@Test
public void testNotInitializedOnAdd() {
Assertions.assertThrows(RedisException.class, () -> {
@ -194,4 +186,17 @@ public class RedissonBloomFilterTest extends RedisDockerTest {
assertThat(newFilter.count()).isEqualTo(1);
assertThat(newFilter.contains("123")).isTrue();
}
@Test
public void testContainsException() {
RBloomFilter<String> f1 = redisson.getBloomFilter("filter");
assertThat(f1.contains("1")).isFalse();
f1.tryInit(100, 0.03);
RBloomFilter<String> f2 = redisson.getBloomFilter("filter");
f2.delete();
f2.tryInit(200, 0.03);
assertThat(f1.contains("1")).isFalse();
}
}

Loading…
Cancel
Save