-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC-2836 added bitmap doc code samples (#280)
- Loading branch information
1 parent
8ef1cb1
commit e913dfc
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// 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 | ||
{ | ||
|
||
[SkipIfRedis(Is.OSSCluster)] | ||
public void run() | ||
{ | ||
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 | ||
|