Bloom Filter usign Redis and Node.js

445 Views Asked by At

I am using @albert-team/rebloom package for implementation of Bloom Filter using Local Redis

const { BloomFilter } = require('@albert-team/rebloom')
const main = async () => {
    const filter = new BloomFilter('filtername', {
      host: 'localhost',
      port: 6379,
    })
    await filter.connect()
  
    console.log(await filter.add('item0')) // 1
    console.log(await filter.exists('item0')) // 1
    console.log(await filter.exists('item1')) // 0
  
    await filter.disconnect()
  }
  
  main().catch((err) => console.error(err))

but i get below error. TypeError: multi.setbit is not a function at /Users/rohit/Downloads/Microservices/POC/node_modules/bloom-redis/lib/index.js:61:15

Two Questions :

  1. How can i resolve the above issue?
  2. Is there any other package of approach i can use for Bloom Filter implementation?
1

There are 1 best solutions below

0
On

Node Redis supports Redis Bloom now. Works like this:

import { createClient } from 'redis';

const client = createClient();
await client.connect();

await client.bf.reserve('mybloom', 0.01, 1000);
await client.bf.add('mybloom', 'foo'),
await client.bf.mAdd('mybloom', [ 'bar', 'baz' ]);

const singleExists = await client.bf.exists('mybloom', 'foo');  // true
const multiExists = await client.bf.mExists('mybloom', [ 'baz', 'qux' ]);  // [ true, false ]