BloomFilter Ruby: Redis backed. fork for jruby use.
Ruby C Objective-C
Pull request Compare This branch is 5 commits ahead, 17 commits behind igrigorik:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

BloomFilter(s) in Ruby / Without Original Native Support

  • Redis-backed getbit/setbit non-counting bloom filter
  • Redis-backed set-based counting (+TTL) bloom filter

Bloom filter is a space-efficient probabilistic data structure that is used to test whether an element is a member of a set. False positives are possible, but false negatives are not. For more detail, check the wikipedia article. Instead of using k different hash functions, this implementation seeds the CRC32 hash with k different initial values (0, 1, ..., k-1). This may or may not give you a good distribution, it all depends on the data.

Performance of the Bloom filter depends on a number of variables:

  • size of the bit array
  • size of the counter bucket
  • number of hash functions


Redis-backed setbit/getbit bloom filter

Uses getbit/setbit on Redis strings - efficient, fast, can be shared by multiple/concurrent processes.

bf =

bf.include?('test')     # => true
bf.include?('blah')     # => false

bf.include?('test')     # => false

Memory footprint

  • 1.0% error rate for 1M items, 10 bits/item: 2.5 mb
  • 1.0% error rate for 150M items, 10 bits per item: 358.52 mb
  • 0.1% error rate for 150M items, 15 bits per item: 537.33 mb

Redis-backed counting bloom filter with TTL's

Uses regular Redis get/set counters to implement a counting filter with optional TTL expiry. Because each "bit" requires its own key in Redis, you do incur a much larger memory overhead.

bf = => 2)

bf.include?('test')     # => true

bf.include?('test')     # => false


Tatsuya Mori (Original C implementation:


MIT License - Copyright (c) 2011 Ilya Grigorik