Advertisement
Beginner Redis, RedisBloom (Probabilistic Data Structures)

How do you add items to a Bloom filter and check if an item might already exist using RedisBloom commands?

Short answer

You use BF.ADD to add an item to a Bloom filter, automatically creating the filter if it does not already exist, and BF.EXISTS to check whether an item has possibly already been added, returning a definite no if the item was certainly never added, or a probable yes that could…

Save Redis mock interview
Advertisement
AModel answer
You use BF.ADD to add an item to a Bloom filter, automatically creating the filter if it does not already exist, and BF.EXISTS to check whether an item has possibly already been added, returning a definite no if the item was certainly never added, or a probable yes that could occasionally be a false positive.
Example

BF.ADD visited_urls 'https://example.com/page1' BF.EXISTS visited_urls 'https://example.com/page1'

Real-world example
A recommendation engine uses a Bloom filter to quickly check whether a specific product has already been recommended to a user, avoiding repetitive suggestions without needing to store an exhaustive list of every past recommendation.
Likely follow-ups
  • What is a false positive rate, and how do you configure it for a Bloom filter?
  • Can you remove an item from a Bloom filter once it has been added?
Related topics