Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@redis/bloom

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@redis/bloom

This package provides support for the [RedisBloom](https://redisbloom.io) module, which adds additional probabilistic data structures to Redis. It extends the [Node Redis client](https://github.com/redis/node-redis) to include functions for each of the R

  • 1.2.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1.8M
decreased by-14.68%
Maintainers
1
Weekly downloads
 
Created

What is @redis/bloom?

@redis/bloom is an npm package that provides probabilistic data structures for Redis, such as Bloom filters, Cuckoo filters, Count-Min Sketch, and Top-K. These data structures are useful for efficiently handling large sets of data with minimal memory usage and are often used in scenarios like caching, deduplication, and approximate counting.

What are @redis/bloom's main functionalities?

Bloom Filter

This example demonstrates how to create a Bloom filter, add an item to it, and check for the existence of an item. Bloom filters are used to test whether an element is a member of a set with a possible false positive rate.

const { createClient } = require('@redis/bloom');

async function bloomFilterExample() {
  const client = createClient();
  await client.connect();

  await client.bf.reserve('myBloom', 0.01, 1000);
  await client.bf.add('myBloom', 'item1');
  const exists = await client.bf.exists('myBloom', 'item1');
  console.log(exists); // true

  await client.disconnect();
}

bloomFilterExample();

Cuckoo Filter

This example shows how to create a Cuckoo filter, add an item, and check for its existence. Cuckoo filters are similar to Bloom filters but support deletion of items.

const { createClient } = require('@redis/bloom');

async function cuckooFilterExample() {
  const client = createClient();
  await client.connect();

  await client.cf.reserve('myCuckoo', 1000);
  await client.cf.add('myCuckoo', 'item1');
  const exists = await client.cf.exists('myCuckoo', 'item1');
  console.log(exists); // true

  await client.disconnect();
}

cuckooFilterExample();

Count-Min Sketch

This example demonstrates how to initialize a Count-Min Sketch, increment the count of an item, and query the count. Count-Min Sketches are used for approximate frequency counting.

const { createClient } = require('@redis/bloom');

async function countMinSketchExample() {
  const client = createClient();
  await client.connect();

  await client.cms.initByDim('myCMS', 2000, 5);
  await client.cms.incrBy('myCMS', 'item1', 5);
  const count = await client.cms.query('myCMS', 'item1');
  console.log(count); // 5

  await client.disconnect();
}

countMinSketchExample();

Top-K

This example shows how to create a Top-K data structure, add items to it, and retrieve the top K items. Top-K is used to maintain a list of the most frequent items.

const { createClient } = require('@redis/bloom');

async function topKExample() {
  const client = createClient();
  await client.connect();

  await client.topk.reserve('myTopK', 3);
  await client.topk.add('myTopK', 'item1', 'item2', 'item3', 'item1');
  const list = await client.topk.list('myTopK');
  console.log(list); // ['item1', 'item2', 'item3']

  await client.disconnect();
}

topKExample();

Other packages similar to @redis/bloom

FAQs

Package last updated on 25 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc