Skip to content

Commit 8a41c09

Browse files
DOC-2592 added doc code sample for Bloom filter (#283)
1 parent ecba417 commit 8a41c09

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/Doc/Bf_tutorial.cs

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// EXAMPLE: bf_tutorial
2+
// HIDE_START
3+
4+
using NRedisStack.RedisStackCommands;
5+
using NRedisStack.Tests;
6+
using StackExchange.Redis;
7+
8+
// HIDE_END
9+
10+
// REMOVE_START
11+
namespace Doc;
12+
[Collection("DocsTests")]
13+
// REMOVE_END
14+
15+
// HIDE_START
16+
public class Bf_tutorial
17+
{
18+
19+
[SkipIfRedis(Is.OSSCluster)]
20+
public void run()
21+
{
22+
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
23+
var db = muxer.GetDatabase();
24+
//REMOVE_START
25+
// Clear any keys here before using them in tests.
26+
db.KeyDelete("bikes:models");
27+
//REMOVE_END
28+
// HIDE_END
29+
30+
31+
// STEP_START bloom
32+
bool res1 = db.BF().Reserve("bikes:models", 0.01, 1000);
33+
Console.WriteLine(res1); // >>> True
34+
35+
bool res2 = db.BF().Add("bikes:models", "Smoky Mountain Striker");
36+
Console.WriteLine(res2); // >>> True
37+
38+
bool res3 = db.BF().Exists("bikes:models", "Smoky Mountain Striker");
39+
Console.WriteLine(res3); // >>> True
40+
41+
bool[] res4 = db.BF().MAdd("bikes:models", new RedisValue[]{
42+
"Rocky Mountain Racer",
43+
"Cloudy City Cruiser",
44+
"Windy City Wippet"
45+
});
46+
Console.WriteLine(string.Join(", ", res4)); // >>> True, True, True
47+
48+
bool[] res5 = db.BF().MExists("bikes:models", new RedisValue[]{
49+
"Rocky Mountain Racer",
50+
"Cloudy City Cruiser",
51+
"Windy City Wippet"
52+
});
53+
Console.WriteLine(string.Join(", ", res5)); // >>> True, True, True
54+
// STEP_END
55+
56+
// Tests for 'bloom' step.
57+
// REMOVE_START
58+
Assert.True(res1);
59+
Assert.True(res2);
60+
Assert.True(res3);
61+
Assert.Equal("True, True, True", string.Join(", ", res4));
62+
Assert.Equal("True, True, True", string.Join(", ", res5));
63+
// REMOVE_END
64+
65+
66+
// HIDE_START
67+
}
68+
}
69+
// HIDE_END
70+

0 commit comments

Comments
 (0)