Redis

Redis Bloom Filter

Redis bloom filter is a Redis module that introduces probabilistic data structures. They provide high accuracy and memory efficiency, especially in large applications.

The bloom filter module provides four specific data types:

  1. Bloom
  2. Cuckoo
  3. Top-k
  4. Count-min sketch

Bloom and Cuckoo Filters

Bloom and cuckoo filters mainly determine if an element is a set member. They are extremely fast and efficient.

Top-K

Top-K data structure is used to keep track of the list of the most frequently seen items.

Count-Min Sketch

On the other hand, the count-min sketch data structure determines the frequency of events. Using this type, you can determine the frequency estimate of a given event.

Redis Install Bloom Filter Module

Before using the Reids Bloom Filter module, you must compile and load it.

Start by cloning the source repository:

$ git clone https://github.com/RedisBloom/RedisBloom

Once the operation is complete, navigate into the repository directory:

$cd RedisBloom

Compile module by running the command:

$ make

Ensure you have the required dependencies for successful compilation.

Edit the Redis configuration file and load the module:

loadmodule /path/to/rebloom.so

You can also load the module from the command line as:

$ redis-server --loadmodule /path/to/rebloom.so

Redis Create Bloom Filter

You can create a new bloom filter by adding a new item as shown in the command below:

127.0.0.1:6379> BF.ADD databases MongoDB

(integer) 1

The command above should add a new bloom filter with the name databases and one item.

To add multiple items to a bloom filter, use the MADD command as shown:

127.0.0.1:6379> BF.MADD databases MySQL PostgreSQL SQL_SERVER

1) (integer) 1

2) (integer) 1

3) (integer) 1

Check if an item exists

To check if an item exists within a bloom filter, run the command:

127.0.0.1:6379> BF.EXISTS databases MongoDB

(integer) 1

Since a bloom filter is a probabilistic data structure, the output indicates a probability the item exists.

If the output is 0, the item does not exist.

You can also check if multiple items exist in the bloom filter using the MEXISTS command.

127.0.0.1:6379> BF.MEXISTS databases MySQL FaunaDB

1) (integer) 1

2) (integer) 0

Closing

This guide covered installing and using the Redis Bloom filter module.

Thanks for reading!!

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list