Skip to content

Commit

Permalink
DOC-2836 added bitmap doc code samples (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-stark-redis committed May 14, 2024
1 parent 8ef1cb1 commit e913dfc
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/Doc/Bitmap_tutorial.cs
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

0 comments on commit e913dfc

Please sign in to comment.