Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC-2836 added bitmap doc code samples #280

Merged
merged 2 commits into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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