# Elixir Redis Bloomfilter

A distributed bloom filter implementation based on Redis. Uses [Erik Dubbelboer's] (
[LUA Redis scripts]( for the bloom filter implementation.

## Installation

Add `redis_bloomfilter` to your list of dependencies in `mix.exs`,
and start its application:

  def deps do
    [{:redis_bloomfilter, "~> 0.1.0"}]

Note that the latest hex version may be higher than what is listed here. You can
find the latest version on [hex]( You should match
the version or alternatively you can use a looser version constraint like `"~> 1.0"`.

## Usage

Assuming that RedisBloomfilter is setup (see below), the usage is a breeze!

iex(2)> RedisBloomfilter.include?("My String")
iex(3)> RedisBloomfilter.insert("My String")
{:ok, "My String"}
iex(4)> RedisBloomfilter.include?("My String")

iex(5)> RedisBloomfilter.include?("My String 2")
iex(7)> RedisBloomfilter.insert("My String 2")
{:ok, "My String 2"}
iex(8)> RedisBloomfilter.include?("My String 2")

iex(9)> RedisBloomfilter.include?("My String 3")
iex(10)> RedisBloomfilter.clear
{:ok, 2}
iex(11)> RedisBloomfilter.include?("My String")

The three public methods are `include?`, `insert`, and `clear`. `clear` is destructive and should be used with care.

## Dependencies

* Redix - Requires that you have setup [Redix]( on your own and can provide
          a name function to the library.

## Configuration

Options to RedisBloomfilter take the following options:

* key_name  - The key prefix that will be used in redis to store the bloom filter. A single bloom filter will
              use multiple keys due to the scaling implementation.
              Default: *bloom-filter*

* size      - The initial size of the number of elements. The bloom filter will scale to any number of elements, but
              will use more keys in redis.
              Default: *100000*

* precision - The approximate precision of the bloom filter. This should be a ratio within the range (0,1)
              Default: *0.01*

The options can be passed into RedisBloomfilter functions, or set in the Application config like so:

config RedisBloomfilter,
  filter_options: [key_name: "custom-key", size: 1000, precision: 0.005],

## Redix Setup

This library assumes that you're using Redix, but doesn't necessarily require it (no mix deps). You do need a module
called Redix that responds to the Redix.command interface, and the easiest way to get that is to use Redix. So that this
library does not need OTP setup, the PID of your Redix process is done via a name. This name defaults to `:redix` but is
customizable via the `pid_fn` Application env option `pid_fn`:

config RedisBloomfilter,
  pid_fn: fn() ->
      id = rem(System.unique_integer([:positive]), 5)

In the above function, a random integer [0,4] is appended to `redix_`. This comes from their
[recommended setup guide](