Skip to content

Commit 8ef1cb1

Browse files
DOC-2844 added code sample for HyperLogLog (#282)
* DOC-2844 added code sample for HyperLogLog * DOC-2844 use hashtags to fix cross-slot errors
1 parent 8a41c09 commit 8ef1cb1

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/Doc/Hll_tutorial.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// EXAMPLE: hll_tutorial
2+
// HIDE_START
3+
4+
using NRedisStack.Tests;
5+
using StackExchange.Redis;
6+
7+
// HIDE_END
8+
9+
// REMOVE_START
10+
namespace Doc;
11+
[Collection("DocsTests")]
12+
// REMOVE_END
13+
14+
// HIDE_START
15+
public class Hll_tutorial
16+
{
17+
18+
[SkipIfRedis(Is.OSSCluster)]
19+
public void run()
20+
{
21+
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
22+
var db = muxer.GetDatabase();
23+
//REMOVE_START
24+
// Clear any keys here before using them in tests.
25+
db.KeyDelete(new RedisKey[] { "{bikes}", "commuter_{bikes}", "all_{bikes}" });
26+
//REMOVE_END
27+
// HIDE_END
28+
29+
30+
// STEP_START pfadd
31+
bool res1 = db.HyperLogLogAdd("{bikes}", new RedisValue[] { "Hyperion", "Deimos", "Phoebe", "Quaoar" });
32+
Console.WriteLine(res1); // >>> True
33+
34+
long res2 = db.HyperLogLogLength("{bikes}");
35+
Console.WriteLine(res2); // >>> 4
36+
37+
bool res3 = db.HyperLogLogAdd("commuter_{bikes}", new RedisValue[] { "Salacia", "Mimas", "Quaoar" });
38+
Console.WriteLine(res3); // >>> True
39+
40+
db.HyperLogLogMerge("all_{bikes}", "{bikes}", "commuter_{bikes}");
41+
long res4 = db.HyperLogLogLength("all_{bikes}");
42+
Console.WriteLine(res4); // >>> 6
43+
// STEP_END
44+
45+
// Tests for 'pfadd' step.
46+
// REMOVE_START
47+
Assert.True(res1);
48+
Assert.Equal(4, res2);
49+
Assert.True(res3);
50+
Assert.Equal(6, res4);
51+
// REMOVE_END
52+
53+
54+
// HIDE_START
55+
}
56+
}
57+
// HIDE_END
58+

0 commit comments

Comments
 (0)