Skip to content

DOC-2844 added code sample for HyperLogLog #282

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

Merged
merged 3 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tests/Doc/Hll_tutorial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// EXAMPLE: hll_tutorial
// HIDE_START

using NRedisStack.Tests;
using StackExchange.Redis;

// HIDE_END

// REMOVE_START
namespace Doc;
[Collection("DocsTests")]
// REMOVE_END

// HIDE_START
public class Hll_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(new RedisKey[] { "{bikes}", "commuter_{bikes}", "all_{bikes}" });
//REMOVE_END
// HIDE_END


// STEP_START pfadd
bool res1 = db.HyperLogLogAdd("{bikes}", new RedisValue[] { "Hyperion", "Deimos", "Phoebe", "Quaoar" });
Console.WriteLine(res1); // >>> True

long res2 = db.HyperLogLogLength("{bikes}");
Console.WriteLine(res2); // >>> 4

bool res3 = db.HyperLogLogAdd("commuter_{bikes}", new RedisValue[] { "Salacia", "Mimas", "Quaoar" });
Console.WriteLine(res3); // >>> True

db.HyperLogLogMerge("all_{bikes}", "{bikes}", "commuter_{bikes}");
long res4 = db.HyperLogLogLength("all_{bikes}");
Console.WriteLine(res4); // >>> 6
// STEP_END

// Tests for 'pfadd' step.
// REMOVE_START
Assert.True(res1);
Assert.Equal(4, res2);
Assert.True(res3);
Assert.Equal(6, res4);
// REMOVE_END


// HIDE_START
}
}
// HIDE_END

Loading