-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updates examples. * Added command link for hset.
- Loading branch information
Simon Prickett
authored
Aug 15, 2022
1 parent
60ad6aa
commit f3462ab
Showing
19 changed files
with
923 additions
and
970 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,80 @@ | ||
// This example demonstrates the use of the Bloom Filter | ||
// in the RedisBloom module (https://redisbloom.io/) | ||
// in the RedisBloom module (https://redis.io/docs/stack/bloom/) | ||
|
||
import { createClient } from 'redis'; | ||
|
||
async function bloomFilter() { | ||
const client = createClient(); | ||
const client = createClient(); | ||
|
||
await client.connect(); | ||
await client.connect(); | ||
|
||
// Delete any pre-existing Bloom Filter. | ||
await client.del('mybloom'); | ||
// Delete any pre-existing Bloom Filter. | ||
await client.del('mybloom'); | ||
|
||
// Reserve a Bloom Filter with configurable error rate and capacity. | ||
// https://oss.redis.com/redisbloom/Bloom_Commands/#bfreserve | ||
try { | ||
await client.bf.reserve('mybloom', 0.01, 1000); | ||
console.log('Reserved Bloom Filter.'); | ||
} catch (e) { | ||
if (e.message.endsWith('item exists')) { | ||
console.log('Bloom Filter already reserved.'); | ||
} else { | ||
console.log('Error, maybe RedisBloom is not installed?:'); | ||
console.log(e); | ||
} | ||
// Reserve a Bloom Filter with configurable error rate and capacity. | ||
// https://redis.io/commands/bf.reserve/ | ||
try { | ||
await client.bf.reserve('mybloom', 0.01, 1000); | ||
console.log('Reserved Bloom Filter.'); | ||
} catch (e) { | ||
if (e.message.endsWith('item exists')) { | ||
console.log('Bloom Filter already reserved.'); | ||
} else { | ||
console.log('Error, maybe RedisBloom is not installed?:'); | ||
console.log(e); | ||
} | ||
} | ||
|
||
// Add items to Bloom Filter individually with BF.ADD command. | ||
await Promise.all([ | ||
client.bf.add('mybloom', 'leibale'), | ||
client.bf.add('mybloom', 'simon'), | ||
client.bf.add('mybloom', 'guy'), | ||
client.bf.add('mybloom', 'suze'), | ||
client.bf.add('mybloom', 'brian'), | ||
client.bf.add('mybloom', 'steve'), | ||
client.bf.add('mybloom', 'kyle'), | ||
client.bf.add('mybloom', 'josefin'), | ||
client.bf.add('mybloom', 'alex'), | ||
client.bf.add('mybloom', 'nava'), | ||
]); | ||
|
||
// Add multiple items to Bloom Filter at once with BF.MADD command. | ||
await client.bf.mAdd('mybloom', [ | ||
'kaitlyn', | ||
'rachel' | ||
]); | ||
// Add items to Bloom Filter individually with BF.ADD command. | ||
// https://redis.io/commands/bf.add/ | ||
await Promise.all([ | ||
client.bf.add('mybloom', 'leibale'), | ||
client.bf.add('mybloom', 'simon'), | ||
client.bf.add('mybloom', 'guy'), | ||
client.bf.add('mybloom', 'suze'), | ||
client.bf.add('mybloom', 'brian'), | ||
client.bf.add('mybloom', 'steve'), | ||
client.bf.add('mybloom', 'kyle'), | ||
client.bf.add('mybloom', 'josefin'), | ||
client.bf.add('mybloom', 'alex'), | ||
client.bf.add('mybloom', 'nava'), | ||
]); | ||
|
||
console.log('Added members to Bloom Filter.'); | ||
// Add multiple items to Bloom Filter at once with BF.MADD command. | ||
// https://redis.io/commands/bf.madd/ | ||
await client.bf.mAdd('mybloom', [ | ||
'kaitlyn', | ||
'rachel' | ||
]); | ||
|
||
// Check whether a member exists with the BF.EXISTS command. | ||
const simonExists = await client.bf.exists('mybloom', 'simon'); | ||
console.log(`simon ${simonExists ? 'may' : 'does not'} exist in the Bloom Filter.`); | ||
console.log('Added members to Bloom Filter.'); | ||
|
||
// Check whether multiple members exist with the BF.MEXISTS command: | ||
const [ lanceExists, leibaleExists ] = await client.bf.mExists('mybloom', [ | ||
'lance', | ||
'leibale' | ||
]); | ||
// Check whether a member exists with the BF.EXISTS command. | ||
// https://redis.io/commands/bf.exists/ | ||
const simonExists = await client.bf.exists('mybloom', 'simon'); | ||
console.log(`simon ${simonExists ? 'may' : 'does not'} exist in the Bloom Filter.`); | ||
|
||
console.log(`lance ${lanceExists ? 'may' : 'does not'} exist in the Bloom Filter.`); | ||
console.log(`leibale ${leibaleExists ? 'may' : 'does not'} exist in the Bloom Filter.`); | ||
// Check whether multiple members exist with the BF.MEXISTS command. | ||
// https://redis.io/commands/bf.mexists/ | ||
const [ lanceExists, leibaleExists ] = await client.bf.mExists('mybloom', [ | ||
'lance', | ||
'leibale' | ||
]); | ||
|
||
// Get stats for the Bloom Filter with the BF.INFO command: | ||
const info = await client.bf.info('mybloom'); | ||
// info looks like this: | ||
// | ||
// { | ||
// capacity: 1000, | ||
// size: 1531, | ||
// numberOfFilters: 1, | ||
// numberOfInsertedItems: 12, | ||
// expansionRate: 2 | ||
// } | ||
console.log(info); | ||
console.log(`lance ${lanceExists ? 'may' : 'does not'} exist in the Bloom Filter.`); | ||
console.log(`leibale ${leibaleExists ? 'may' : 'does not'} exist in the Bloom Filter.`); | ||
|
||
await client.quit(); | ||
} | ||
// Get stats for the Bloom Filter with the BF.INFO command. | ||
// https://redis.io/commands/bf.info/ | ||
const info = await client.bf.info('mybloom'); | ||
// info looks like this: | ||
// | ||
// { | ||
// capacity: 1000, | ||
// size: 1531, | ||
// numberOfFilters: 1, | ||
// numberOfInsertedItems: 12, | ||
// expansionRate: 2 | ||
// } | ||
console.log(info); | ||
|
||
bloomFilter(); | ||
await client.quit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.