Skip to content

Commit e913dfc

Browse files
DOC-2836 added bitmap doc code samples (#280)
1 parent 8ef1cb1 commit e913dfc

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

tests/Doc/Bitmap_tutorial.cs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// EXAMPLE: bitmap_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 Bitmap_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("pings:2024-01-01-00:00");
26+
//REMOVE_END
27+
// HIDE_END
28+
29+
30+
// STEP_START ping
31+
bool res1 = db.StringSetBit("pings:2024-01-01-00:00", 123, true);
32+
Console.WriteLine(res1); // >>> 0
33+
34+
bool res2 = db.StringGetBit("pings:2024-01-01-00:00", 123);
35+
Console.WriteLine(res2); // >>> True
36+
37+
bool res3 = db.StringGetBit("pings:2024-01-01-00:00", 456);
38+
Console.WriteLine(res3); // >>> False
39+
// STEP_END
40+
41+
// Tests for 'ping' step.
42+
// REMOVE_START
43+
Assert.False(res1);
44+
Assert.True(res2);
45+
Assert.False(res3);
46+
// REMOVE_END
47+
48+
49+
// STEP_START bitcount
50+
bool res4 = db.StringSetBit("pings:2024-01-01-00:00", 123, true);
51+
long res5 = db.StringBitCount("pings:2024-01-01-00:00");
52+
Console.WriteLine(res5); // >>> 1
53+
// STEP_END
54+
55+
// Tests for 'bitcount' step.
56+
// REMOVE_START
57+
Assert.True(res4);
58+
Assert.Equal(1, res5);
59+
// REMOVE_END
60+
61+
62+
// HIDE_START
63+
}
64+
}
65+
// HIDE_END
66+

0 commit comments

Comments
 (0)