
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
@redis/bloom
Advanced tools
This package provides support for the [RedisBloom](https://redis.io/docs/data-types/probabilistic/) module, which adds additional probabilistic data structures to Redis.
@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.
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();
The 'bloom-filter' package provides a simple implementation of Bloom filters in JavaScript. It is less feature-rich compared to @redis/bloom and does not integrate with Redis, making it suitable for in-memory operations only.
The 'cuckoo-filter' package offers a JavaScript implementation of Cuckoo filters. Similar to 'bloom-filter', it does not integrate with Redis and is intended for in-memory use cases.
The 'count-min-sketch' package provides a JavaScript implementation of the Count-Min Sketch data structure. It is useful for approximate frequency counting but lacks the Redis integration provided by @redis/bloom.
This package provides support for the RedisBloom module, which adds additional probabilistic data structures to Redis.
Should be used with redis
/@redis/client
.
:warning: To use these extra commands, your Redis server must have the RedisBloom module installed.
RedisBloom provides the following probabilistic data structures:
For some examples, see bloom-filter.js
, cuckoo-filter.js
, count-min-sketch.js
and topk.js
in the examples folder.
FAQs
This package provides support for the [RedisBloom](https://redis.io/docs/data-types/probabilistic/) module, which adds additional probabilistic data structures to Redis.
The npm package @redis/bloom receives a total of 3,162,898 weekly downloads. As such, @redis/bloom popularity was classified as popular.
We found that @redis/bloom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.