-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into DOC-2841-code-samples-for-bitfield-csharp
- Loading branch information
Showing
8 changed files
with
630 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,70 @@ | ||
// EXAMPLE: bf_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 Bf_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 bloom | ||
bool res1 = db.BF().Reserve("bikes:models", 0.01, 1000); | ||
Console.WriteLine(res1); // >>> True | ||
|
||
bool res2 = db.BF().Add("bikes:models", "Smoky Mountain Striker"); | ||
Console.WriteLine(res2); // >>> True | ||
|
||
bool res3 = db.BF().Exists("bikes:models", "Smoky Mountain Striker"); | ||
Console.WriteLine(res3); // >>> True | ||
|
||
bool[] res4 = db.BF().MAdd("bikes:models", new RedisValue[]{ | ||
"Rocky Mountain Racer", | ||
"Cloudy City Cruiser", | ||
"Windy City Wippet" | ||
}); | ||
Console.WriteLine(string.Join(", ", res4)); // >>> True, True, True | ||
|
||
bool[] res5 = db.BF().MExists("bikes:models", new RedisValue[]{ | ||
"Rocky Mountain Racer", | ||
"Cloudy City Cruiser", | ||
"Windy City Wippet" | ||
}); | ||
Console.WriteLine(string.Join(", ", res5)); // >>> True, True, True | ||
// STEP_END | ||
|
||
// Tests for 'bloom' step. | ||
// REMOVE_START | ||
Assert.True(res1); | ||
Assert.True(res2); | ||
Assert.True(res3); | ||
Assert.Equal("True, True, True", string.Join(", ", res4)); | ||
Assert.Equal("True, True, True", string.Join(", ", res5)); | ||
// REMOVE_END | ||
|
||
|
||
// HIDE_START | ||
} | ||
} | ||
// HIDE_END | ||
|
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 | ||
|
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,71 @@ | ||
// EXAMPLE: cms_tutorial | ||
// HIDE_START | ||
|
||
using NRedisStack.CountMinSketch.DataTypes; | ||
using NRedisStack.RedisStackCommands; | ||
using NRedisStack.Tests; | ||
using StackExchange.Redis; | ||
|
||
// HIDE_END | ||
|
||
// REMOVE_START | ||
namespace Doc; | ||
[Collection("DocsTests")] | ||
// REMOVE_END | ||
|
||
// HIDE_START | ||
public class Cms_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:profit"); | ||
//REMOVE_END | ||
// HIDE_END | ||
|
||
|
||
// STEP_START cms | ||
bool res1 = db.CMS().InitByProb("bikes:profit", 0.001, 0.002); | ||
Console.WriteLine(res1); // >>> True | ||
|
||
long res2 = db.CMS().IncrBy("bikes:profit", "Smoky Mountain Striker", 100); | ||
Console.WriteLine(res2); // >>> 100 | ||
|
||
long[] res3 = db.CMS().IncrBy("bikes:profit", | ||
new Tuple<RedisValue, long>[]{ | ||
new Tuple<RedisValue, long>("Rocky Mountain Racer", 200), | ||
new Tuple<RedisValue, long>("Cloudy City Cruiser", 150) | ||
} | ||
); | ||
Console.WriteLine(string.Join(", ", res3)); // >>> 200, 150 | ||
|
||
long[] res4 = db.CMS().Query("bikes:profit", new RedisValue[] { "Smoky Mountain Striker" }); | ||
Console.WriteLine(string.Join(", ", res4)); // >>> 100 | ||
|
||
CmsInformation res5 = db.CMS().Info("bikes:profit"); | ||
Console.WriteLine($"Width: {res5.Width}, Depth: {res5.Depth}, Count: {res5.Count}"); | ||
// >>> Width: 2000, Depth: 9, Count: 450 | ||
// STEP_END | ||
|
||
// Tests for 'cms' step. | ||
// REMOVE_START | ||
Assert.True(res1); | ||
Assert.Equal(100, res2); | ||
Assert.Equal("200, 150", string.Join(", ", res3)); | ||
Assert.Equal("100", string.Join(", ", res4)); | ||
Assert.Equal(2000, res5.Width); | ||
Assert.Equal(9, res5.Depth); | ||
Assert.Equal(450, res5.Count); | ||
// REMOVE_END | ||
|
||
|
||
// HIDE_START | ||
} | ||
} | ||
// HIDE_END | ||
|
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,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 | ||
|
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,87 @@ | ||
// EXAMPLE: geo_tutorial | ||
// HIDE_START | ||
|
||
using NRedisStack.Tests; | ||
using StackExchange.Redis; | ||
|
||
// HIDE_END | ||
|
||
// REMOVE_START | ||
namespace Doc; | ||
[Collection("DocsTests")] | ||
// REMOVE_END | ||
|
||
// HIDE_START | ||
public class Geo_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:rentable"); | ||
//REMOVE_END | ||
// HIDE_END | ||
|
||
|
||
// STEP_START geoadd | ||
bool res1 = db.GeoAdd("bikes:rentable", -122.27652, 37.805186, "station:1"); | ||
Console.WriteLine(res1); // >>> True | ||
|
||
bool res2 = db.GeoAdd("bikes:rentable", -122.2674626, 37.8062344, "station:2"); | ||
Console.WriteLine(res2); // >>> True | ||
|
||
bool res3 = db.GeoAdd("bikes:rentable", -122.2469854, 37.8104049, "station:3"); | ||
Console.WriteLine(res3); // >>> True | ||
// STEP_END | ||
|
||
// Tests for 'geoadd' step. | ||
// REMOVE_START | ||
Assert.True(res1); | ||
Assert.True(res2); | ||
Assert.True(res3); | ||
// REMOVE_END | ||
|
||
|
||
// STEP_START geosearch | ||
GeoRadiusResult[] res4 = db.GeoSearch("bikes:rentable", | ||
-122.27652, | ||
37.805186, | ||
new GeoSearchCircle(5, GeoUnit.Kilometers) | ||
); | ||
|
||
foreach (GeoRadiusResult member in res4) | ||
{ | ||
Console.WriteLine($"Member: '{member.Member}', distance: {member.Distance}, position: {member.Position}"); | ||
} | ||
// >>> Member: 'station:1', distance: 0.0001, position: -122.27652043104172 37.80518485897756 | ||
// >>> Member: 'station:2', distance: 0.8047, position: -122.26745992898941 37.80623423353753 | ||
// >>> Member: 'station:3', distance: 2.6596, position: -122.24698394536972 37.81040384984464 | ||
// STEP_END | ||
|
||
// Tests for 'geosearch' step. | ||
// REMOVE_START | ||
Assert.Equal(3, res4.Length); | ||
Assert.Equal( | ||
"Member: 'station:1', distance: 0.0001, position: -122.27652043104172 37.80518485897756", | ||
$"Member: '{res4[0].Member}', distance: {res4[0].Distance}, position: {res4[0].Position}" | ||
); | ||
Assert.Equal( | ||
"Member: 'station:2', distance: 0.8047, position: -122.26745992898941 37.80623423353753", | ||
$"Member: '{res4[1].Member}', distance: {res4[1].Distance}, position: {res4[1].Position}" | ||
); | ||
Assert.Equal( | ||
"Member: 'station:3', distance: 2.6596, position: -122.24698394536972 37.81040384984464", | ||
$"Member: '{res4[2].Member}', distance: {res4[2].Distance}, position: {res4[2].Position}" | ||
); | ||
// REMOVE_END | ||
|
||
|
||
// HIDE_START | ||
} | ||
} | ||
// HIDE_END | ||
|
Oops, something went wrong.