Java Code Examples for org.redisson.api.RBloomFilter#tryInit()

The following examples show how to use org.redisson.api.RBloomFilter#tryInit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonBloomFilterTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    RBloomFilter<String> filter = redisson.getBloomFilter("filter");
    filter.tryInit(550000000L, 0.03);

    assertThat(filter.contains("123")).isFalse();
    assertThat(filter.add("123")).isTrue();
    assertThat(filter.contains("123")).isTrue();
    assertThat(filter.add("123")).isFalse();
    assertThat(filter.count()).isEqualTo(1);

    assertThat(filter.contains("hflgs;jl;ao1-32471320o31803-24")).isFalse();
    assertThat(filter.add("hflgs;jl;ao1-32471320o31803-24")).isTrue();
    assertThat(filter.contains("hflgs;jl;ao1-32471320o31803-24")).isTrue();
    assertThat(filter.count()).isEqualTo(2);
}
 
Example 2
Source File: DefaultRedisQueue.java    From SeimiCrawler with Apache License 2.0 5 votes vote down vote up
private RBloomFilter<String> getFilter(String crawlerName){
    RBloomFilter<String> bloomFilter = bloomFilterCache.get(crawlerName);
    if (bloomFilter == null){
        bloomFilter = redisson.getBloomFilter(setNamePrefix + crawlerName, new StringCodec());
        bloomFilter.tryInit(expectedInsertions, falseProbability);
        bloomFilterCache.put(crawlerName,bloomFilter);
    }
    return bloomFilter;
}
 
Example 3
Source File: RedissonBloomFilterTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfig() {
    RBloomFilter<String> filter = redisson.getBloomFilter("filter");
    filter.tryInit(100, 0.03);
    assertThat(filter.getExpectedInsertions()).isEqualTo(100);
    assertThat(filter.getFalseProbability()).isEqualTo(0.03);
    assertThat(filter.getHashIterations()).isEqualTo(5);
    assertThat(filter.getSize()).isEqualTo(729);
}
 
Example 4
Source File: RedissonBloomFilterTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testFalseProbability1() {
    RBloomFilter<String> filter = redisson.getBloomFilter("filter");
    filter.tryInit(1, -1);
}
 
Example 5
Source File: RedissonBloomFilterTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testFalseProbability2() {
    RBloomFilter<String> filter = redisson.getBloomFilter("filter");
    filter.tryInit(1, 2);
}
 
Example 6
Source File: RedissonBloomFilterTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testSizeZero() {
    RBloomFilter<String> filter = redisson.getBloomFilter("filter");
    filter.tryInit(1, 1);
}