npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bloomfilter-redis

v0.1.2

Published

A package implementing bloom filter using redis as backend.

Downloads

36

Readme

bloomfilter-redis

Linux Build Status Windows Build Status

Bloomfilter-redis is a node.js package implementing bloom filter using redis as backend. 🚢

Features

  • use 32bit murmur3 and FNV-1a for double hashing

  • depends on redis package

  • you specify the filter size in redis, up to 512M

Requirements

  • Redis-server installed and running
  • Node.js >= 6

Install

npm install bloomfilter-redis

Usage Example

const BloomFilter = require('bloomfilter-redis');
const redis = require("redis");

let bf = new BloomFilter({//all params have a default value, and I choose some to present below
  redisSize: 16, // this will create a string value which is 16 MegaBytes in length
  hashesNum: 8, // how many hash functions do we use
  redisKey: 'test', //this will create a string which keyname is `test`
  redisClient: redis.createClient(), //you can choose to create the client by yourself
});

promise = bf.init(); // invokes `SETBIT` to allocate memory in redis.For details https://redis.io/commands/setbit

promise.then(() => {
    return bf.add('abc'); // add "abc"
  })
  .then(() => {
    return bf.add('hello'); // add "hello"
  })
  .then(() => {
    return bf.add('world'); // add "world"
  })
  .then(() => {
    return bf.add('nihao'); // add "nihao"
  })
  .then(() => {
    return bf.contains('hola');
  })
  .then((result) => {
    console.log(`"hola" in the set? ${result}`); // "hola" in the set? false
  })
  .then(() => {
    return bf.contains('hello');
  })
  .then((result) => {
    console.log(`"hello" in the set? ${result}`); // "hello" in the set? true
  }).catch(function(err) {
    console.error(err);
  });

Or for an easier way, use promise.all()

const BloomFilter = require('bloomfilter-redis');
const redis = require("redis");

let bf = new BloomFilter();

promise = bf.init();
// both array has `I love you`
arr = ['我爱你', 'I love you', 'je t\'aime', 'ich liebe dich', 'Ti Amo', 'te amo vos amo'];
testArr = ['사랑해요', 'I love you', '爱してる'];

promiseAddArr = [];
promiseContainsArr = [];


arr.forEach(str => {
  promiseAddArr.push(bf.add(str)); // assembly add tasks
});

testArr.forEach(str => {
  promiseContainsArr.push(bf.contains(str)); // assembly contains tasks
});

//lauch!
Promise.all(promiseAddArr).then(() => {
  Promise.all(promiseContainsArr).then(results => {
    console.log(results); // [ false, true, false ]. Yeah, that's the right answer
  })
});

Note

  • BloomFilter.init,BloomFilter.add and BloomFilter.contains all returns a Promise.

  • As there are various options when creating a redis-client using redis.createClient method, it may be a good choice to let users create the redis-client by themselves. Pass the redis-client as a parameter when contructing BloomFilter.

Why choose 32bit hash

LICENCE

MIT