Skip to content

Commit ecba417

Browse files
DOC-2848 added doc code sample for Cuckoo filter (#284)
1 parent 32bfbce commit ecba417

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/Doc/Cuckoo_tutorial.cs

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// EXAMPLE: cuckoo_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 Cuckoo_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 cuckoo
32+
bool res1 = db.CF().Reserve("bikes:models", 1000000);
33+
Console.WriteLine(res1); // >>> True
34+
35+
bool res2 = db.CF().Add("bikes:models", "Smoky Mountain Striker");
36+
Console.WriteLine(res2); // >>> True
37+
38+
bool res3 = db.CF().Exists("bikes:models", "Smoky Mountain Striker");
39+
Console.WriteLine(res3); // >>> True
40+
41+
bool res4 = db.CF().Exists("bikes:models", "Terrible Bike Name");
42+
Console.WriteLine(res4); // >>> False
43+
44+
bool res5 = db.CF().Del("bikes:models", "Smoky Mountain Striker");
45+
Console.WriteLine(res5); // >>> True
46+
// STEP_END
47+
48+
// Tests for 'cuckoo' step.
49+
// REMOVE_START
50+
Assert.True(res1);
51+
Assert.True(res2);
52+
Assert.True(res3);
53+
Assert.False(res4);
54+
Assert.True(res5);
55+
// REMOVE_END
56+
57+
58+
// HIDE_START
59+
}
60+
}
61+
// HIDE_END
62+

0 commit comments

Comments
 (0)