Skip to content

Commit

Permalink
DOC-2848 added doc code sample for Cuckoo filter (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-stark-redis committed May 14, 2024
1 parent 32bfbce commit ecba417
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/Doc/Cuckoo_tutorial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// EXAMPLE: cuckoo_tutorial
// HIDE_START

using NRedisStack.RedisStackCommands;
using NRedisStack.Tests;
using StackExchange.Redis;

// HIDE_END

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

// HIDE_START
public class Cuckoo_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("bikes:models");
//REMOVE_END
// HIDE_END


// STEP_START cuckoo
bool res1 = db.CF().Reserve("bikes:models", 1000000);
Console.WriteLine(res1); // >>> True

bool res2 = db.CF().Add("bikes:models", "Smoky Mountain Striker");
Console.WriteLine(res2); // >>> True

bool res3 = db.CF().Exists("bikes:models", "Smoky Mountain Striker");
Console.WriteLine(res3); // >>> True

bool res4 = db.CF().Exists("bikes:models", "Terrible Bike Name");
Console.WriteLine(res4); // >>> False

bool res5 = db.CF().Del("bikes:models", "Smoky Mountain Striker");
Console.WriteLine(res5); // >>> True
// STEP_END

// Tests for 'cuckoo' step.
// REMOVE_START
Assert.True(res1);
Assert.True(res2);
Assert.True(res3);
Assert.False(res4);
Assert.True(res5);
// REMOVE_END


// HIDE_START
}
}
// HIDE_END

0 comments on commit ecba417

Please sign in to comment.