diff --git a/content/develop/clients/dotnet/prob.md b/content/develop/clients/dotnet/prob.md index 103419f79..2b6b04d09 100644 --- a/content/develop/clients/dotnet/prob.md +++ b/content/develop/clients/dotnet/prob.md @@ -99,49 +99,16 @@ add. The following example adds some names to a Bloom filter representing a list of users and checks for the presence or absence of users in the list. Note that you must use the `BF()` method to access the Bloom filter commands. - -```cs -bool[] res1 = db.BF().MAdd( - "recorded_users", "andy", "cameron", "david", "michelle" -); -Console.WriteLine(string.Join(", ", res1)); -// >>> true, true, true, true - -bool res2 = db.BF().Exists("recorded_users", "cameron"); -Console.WriteLine(res2); // >>> true - -bool res3 = db.BF().Exists("recorded_users", "kaitlyn"); -Console.WriteLine(res3); // >>> false -``` +{{< clients-example home_prob_dts bloom "C#" >}} +{{< /clients-example >}} A Cuckoo filter has similar features to a Bloom filter, but also supports a deletion operation to remove hashes from a set, as shown in the example below. Note that you must use the `CF()` method to access the Cuckoo filter commands. - -```cs -bool res4 = db.CF().Add("other_users", "paolo"); -Console.WriteLine(res4); // >>> true - -bool res5 = db.CF().Add("other_users", "kaitlyn"); -Console.WriteLine(res5); // >>> true - -bool res6 = db.CF().Add("other_users", "rachel"); -Console.WriteLine(res6); // >>> true - -bool[] res7 = db.CF().MExists("other_users", "paolo", "rachel", "andy"); -Console.WriteLine(string.Join(", ", res7)); -// >>> true, true, false - -bool res8 = db.CF().Del("other_users", "paolo"); -Console.WriteLine(res8); // >>> true - -bool res9 = db.CF().Exists("other_users", "paolo"); -Console.WriteLine(res9); // >>> false -``` +{{< clients-example home_prob_dts cuckoo "C#" >}} +{{< /clients-example >}} Which of these two data types you choose depends on your use case. Bloom filters are generally faster than Cuckoo filters when adding new items, @@ -161,35 +128,8 @@ You can also merge two or more HyperLogLogs to find the cardinality of the [union](https://en.wikipedia.org/wiki/Union_(set_theory)) of the sets they represent. - -```cs -bool res10 = db.HyperLogLogAdd( - "group:1", - new RedisValue[] { "andy", "cameron", "david" } -); -Console.WriteLine(res10); // >>> true - -long res11 = db.HyperLogLogLength("group:1"); -Console.WriteLine(res11); // >>> 3 - -bool res12 = db.HyperLogLogAdd( - "group:2", - new RedisValue[] { "kaitlyn", "michelle", "paolo", "rachel" } -); -Console.WriteLine(res12); // >>> true - -long res13 = db.HyperLogLogLength("group:2"); -Console.WriteLine(res13); // >>> 4 - -db.HyperLogLogMerge( - "both_groups", - "group:1", "group:2" -); - -long res14 = db.HyperLogLogLength("both_groups"); -Console.WriteLine(res14); // >>> 7 -``` +{{< clients-example home_prob_dts hyperloglog "C#" >}} +{{< /clients-example >}} The main benefit that HyperLogLogs offer is their very low memory usage. They can count up to 2^64 items with less than @@ -229,44 +169,8 @@ a Count-min sketch object, add data to it, and then query it. Note that you must use the `CMS()` method to access the Count-min sketch commands. - -```cs -// Specify that you want to keep the counts within 0.01 -// (1%) of the true value with a 0.005 (0.5%) chance -// of going outside this limit. -bool res15 = db.CMS().InitByProb("items_sold", 0.01, 0.005); -Console.WriteLine(res15); // >>> true - -long[] res16 = db.CMS().IncrBy( - "items_sold", - new Tuple[]{ - new("bread", 300), - new("tea", 200), - new("coffee", 200), - new("beer", 100) - } -); -Console.WriteLine(string.Join(", ", res16)); -// >>> 300, 200, 200, 100 - -long[] res17 = db.CMS().IncrBy( - "items_sold", - new Tuple[]{ - new("bread", 100), - new("coffee", 150), - } -); -Console.WriteLine(string.Join(", ", res17)); -// >>> 400, 350 - -long[] res18 = db.CMS().Query( - "items_sold", - "bread", "tea", "coffee", "beer" -); -Console.WriteLine(string.Join(", ", res18)); -// >>> 400, 200, 350, 100 -``` +{{< clients-example home_prob_dts cms "C#" >}} +{{< /clients-example >}} The advantage of using a CMS over keeping an exact count with a [sorted set]({{< relref "/develop/data-types/sorted-sets" >}}) @@ -298,53 +202,8 @@ shows how to merge two or more t-digest objects to query the combined data set. Note that you must use the `TDIGEST()` method to access the t-digest commands. - -```cs -bool res19 = db.TDIGEST().Create("male_heights"); -Console.WriteLine(res19); // >>> true - -bool res20 = db.TDIGEST().Add( - "male_heights", - 175.5, 181, 160.8, 152, 177, 196, 164 -); -Console.WriteLine(res20); // >>> true - -double res21 = db.TDIGEST().Min("male_heights"); -Console.WriteLine(res21); // >>> 152.0 - -double res22 = db.TDIGEST().Max("male_heights"); -Console.WriteLine(res22); // >>> 196.0 - -double[] res23 = db.TDIGEST().Quantile("male_heights", 0.75); -Console.WriteLine(string.Join(", ", res23)); // >>> 181.0 - -// Note that the CDF value for 181.0 is not exactly -// 0.75. Both values are estimates. -double[] res24 = db.TDIGEST().CDF("male_heights", 181.0); -Console.WriteLine(string.Join(", ", res24)); // >>> 0.7857142857142857 - -bool res25 = db.TDIGEST().Create("female_heights"); -Console.WriteLine(res25); // >>> true - -bool res26 = db.TDIGEST().Add( - "female_heights", - 155.5, 161, 168.5, 170, 157.5, 163, 171 -); -Console.WriteLine(res26); // >>> true - -double[] res27 = db.TDIGEST().Quantile("female_heights", 0.75); -Console.WriteLine(string.Join(", ", res27)); // >>> 170.0 - -// Specify 0 for `compression` and false for `override`. -bool res28 = db.TDIGEST().Merge( - "all_heights", 0, false, "male_heights", "female_heights" -); -Console.WriteLine(res28); // >>> true - -double[] res29 = db.TDIGEST().Quantile("all_heights", 0.75); -Console.WriteLine(string.Join(", ", res29)); // >>> 175.5 -``` +{{< clients-example home_prob_dts tdigest "C#" >}} +{{< /clients-example >}} A t-digest object also supports several other related commands, such as querying by rank. See the @@ -366,54 +225,5 @@ top *k* items and query whether or not a given item is in the list. Note that you must use the `TOPK()` method to access the Top-K commands. - -```cs -bool res30 = db.TOPK().Reserve("top_3_songs", 3, 7, 8, 0.9); -Console.WriteLine(res30); // >>> true - -RedisResult[] res31 = db.TOPK().IncrBy( - "top_3_songs", - new Tuple[] { - new("Starfish Trooper", 3000), - new("Only one more time", 1850), - new("Rock me, Handel", 1325), - new("How will anyone know?", 3890), - new("Average lover", 4098), - new("Road to everywhere", 770) - } -); -Console.WriteLine( - string.Join( - ", ", - string.Join( - ", ", - res31.Select( - r => $"{(r.IsNull ? "Null" : r)}" - ) - ) - ) -); -// >>> Null, Null, Null, Rock me, Handel, Only one more time, Null - -RedisResult[] res32 = db.TOPK().List("top_3_songs"); -Console.WriteLine( - string.Join( - ", ", - string.Join( - ", ", - res32.Select( - r => $"{(r.IsNull ? "Null" : r)}" - ) - ) - ) -); -// >>> Average lover, How will anyone know?, Starfish Trooper - -bool[] res33 = db.TOPK().Query( - "top_3_songs", - "Starfish Trooper", "Road to everywhere" -); -Console.WriteLine(string.Join(", ", res33)); -// >>> true, false -``` +{{< clients-example home_prob_dts topk "C#" >}} +{{< /clients-example >}}