Baqend / Orestes-Bloomfilter

Library of different Bloom filters in Java with optional Redis-backing, counting and many hashing options.
Other
839 stars 245 forks source link

Inability to have multiple bloom filters stored in redis? #3

Closed smitchelus closed 10 years ago

smitchelus commented 11 years ago

Hi, I'm attempting to use your Redis backed bloomfilter, but it appears that it always stores the filter under a hardcoded key called "normalbloomfilter". How can I have a second bloom filter without overwriting the first one?

DivineTraube commented 11 years ago

Hi, thanks for raising the issue. The problem you describe is in fact present, as every Bloomfilter will use the same keys. I will fix it soon.

smitchelus commented 11 years ago

Cool, thanks!

ChrisCurtin commented 10 years ago

I have submitted a pull request with this feature (Scott and I work together).

DivineTraube commented 10 years ago

The feature is now implemented using the Builder, Bloom filter can now be assigned names, that will be used to distinguish them:

String host = "localhost";
int port = 6379;
String filterName = "normalbloomfilter";
//Open a Redis-backed Bloom filter
BloomFilter<String> bfr = new FilterBuilder(1000, 0.01)
    .name(filterName) //use a distinct name
    .redisBacked(true)
    .redisHost(host) //Default is localhost
    .redisPort(port) //Default is standard 6379
    .buildBloomFilter();

bfr.add("cow");

//Open the same Bloom filter from anywhere else
BloomFilter<String> bfr2 = new FilterBuilder(1000, 0.01)
    .name(filterName) //load the same filter
    .redisBacked(true)
    .buildBloomFilter();
bfr2.add("bison");

print(bfr.contains("cow")); //true
print(bfr.contains("bison")); //true