Skip to content

DOC-5510 local examples for time series and client-specific pages #1893

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
Jul 29, 2025
Merged
Show file tree
Hide file tree
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
215 changes: 13 additions & 202 deletions content/develop/clients/dotnet/prob.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 >}} -->
{{< 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 >}} -->
{{< 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,
Expand All @@ -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 >}} -->
{{< 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
Expand Down Expand Up @@ -228,44 +168,9 @@ of going outside this limit. The example below shows how to create
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<RedisValue, long>[]{
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<RedisValue, long>[]{
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 >}} -->

{{< 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" >}})
Expand Down Expand Up @@ -297,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 >}} -->
{{< 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
Expand All @@ -365,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<RedisValue, long>[] {
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 >}} -->
{{< clients-example home_prob_dts topk "C#" >}}
{{< /clients-example >}}
64 changes: 6 additions & 58 deletions content/develop/clients/dotnet/transpipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,8 @@ versions of the standard command methods
buffered in the pipeline and only execute when you call the `Execute()`
method on the pipeline object.

```cs
var pipeline = new Pipeline(db);

for (int i = 0; i < 5; i++)
{
pipeline.Db.StringSetAsync($"seat:{i}", $"#{i}");
}
pipeline.Execute();

var resp1 = db.StringGet("seat:0");
Console.WriteLine(resp1); // >>> #0

var resp2 = db.StringGet("seat:3");
Console.WriteLine(resp2); // >>> #3

var resp3 = db.StringGet("seat:4");
Console.WriteLine(resp2); // >>> #4
```
<!--< clients-example pipe_trans_tutorial basic_pipe "C#" >}}
< /clients-example >}} -->
{{< clients-example pipe_trans_tutorial basic_pipe "C#" >}}
{{< /clients-example >}}

## Execute a transaction

Expand All @@ -65,26 +47,8 @@ instance of the `Transaction` class, call async command methods
on that object, and then call the transaction object's
`Execute()` method to execute it.

```cs
var trans = new Transaction(db);

trans.Db.StringIncrementAsync("counter:1", 1);
trans.Db.StringIncrementAsync("counter:2", 2);
trans.Db.StringIncrementAsync("counter:3", 3);

trans.Execute();

var resp4 = db.StringGet("counter:1");
Console.WriteLine(resp4); // >>> 1

var resp5 = db.StringGet("counter:2");
Console.WriteLine(resp5); // >>> 2

var resp6 = db.StringGet("counter:3");
Console.WriteLine(resp6); // >>> 3
```
<!--< clients-example pipe_trans_tutorial basic_trans "C#" >}}
< /clients-example >}} -->
{{< clients-example pipe_trans_tutorial basic_trans "C#" >}}
{{< /clients-example >}}

## Watch keys for changes

Expand Down Expand Up @@ -113,24 +77,8 @@ For example, the `KeyNotExists` condition aborts the transaction
if a specified key exists or is added by another client while the
transaction executes:

```cs
var watchedTrans = new Transaction(db);

watchedTrans.AddCondition(Condition.KeyNotExists("customer:39182"));

watchedTrans.Db.HashSetAsync(
"customer:39182",
new HashEntry[]{
new HashEntry("name", "David"),
new HashEntry("age", "27")
}
);

bool succeeded = watchedTrans.Execute();
Console.WriteLine(succeeded); // >>> true
```
<!--< clients-example pipe_trans_tutorial trans_watch "C#" >}}
< /clients-example >}} -->
{{< clients-example pipe_trans_tutorial trans_watch "C#" >}}
{{< /clients-example >}}

You can also use a `When` condition on certain individual commands to
specify that they only execute when a certain condition holds
Expand Down
Loading
Loading