forked from redis/NRedisStack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitmap_tutorial.cs
77 lines (61 loc) · 1.98 KB
/
Bitmap_tutorial.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// EXAMPLE: bitmap_tutorial
// HIDE_START
using NRedisStack.Tests;
using StackExchange.Redis;
// HIDE_END
// REMOVE_START
namespace Doc;
[Collection("DocsTests")]
// REMOVE_END
// HIDE_START
public class Bitmap_tutorial
// REMOVE_START
: AbstractNRedisStackTest, IDisposable
// REMOVE_END
{
// REMOVE_START
public Bitmap_tutorial(EndpointsFixture fixture) : base(fixture) { }
[SkippableFact]
// REMOVE_END
public void run()
{
//REMOVE_START
// This is needed because we're constructing ConfigurationOptions in the test before calling GetConnection
SkipIfTargetConnectionDoesNotExist(EndpointsFixture.Env.Standalone);
var _ = GetCleanDatabase(EndpointsFixture.Env.Standalone);
//REMOVE_END
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
//REMOVE_START
// Clear any keys here before using them in tests.
db.KeyDelete("pings:2024-01-01-00:00");
//REMOVE_END
// HIDE_END
// STEP_START ping
bool res1 = db.StringSetBit("pings:2024-01-01-00:00", 123, true);
Console.WriteLine(res1); // >>> 0
bool res2 = db.StringGetBit("pings:2024-01-01-00:00", 123);
Console.WriteLine(res2); // >>> True
bool res3 = db.StringGetBit("pings:2024-01-01-00:00", 456);
Console.WriteLine(res3); // >>> False
// STEP_END
// Tests for 'ping' step.
// REMOVE_START
Assert.False(res1);
Assert.True(res2);
Assert.False(res3);
// REMOVE_END
// STEP_START bitcount
bool res4 = db.StringSetBit("pings:2024-01-01-00:00", 123, true);
long res5 = db.StringBitCount("pings:2024-01-01-00:00");
Console.WriteLine(res5); // >>> 1
// STEP_END
// Tests for 'bitcount' step.
// REMOVE_START
Assert.True(res4);
Assert.Equal(1, res5);
// REMOVE_END
// HIDE_START
}
}
// HIDE_END