Skip to content

Commit 141b14d

Browse files
Merge pull request #1893 from redis/DOC-5510-local-examples
DOC-5510 local examples for time series and client-specific pages
2 parents 8d01d00 + d67659b commit 141b14d

File tree

13 files changed

+3820
-606
lines changed

13 files changed

+3820
-606
lines changed

content/develop/clients/dotnet/prob.md

Lines changed: 13 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -99,49 +99,16 @@ add. The following example adds some names to a Bloom filter representing
9999
a list of users and checks for the presence or absence of users in the list.
100100
Note that you must use the `BF()` method to access the Bloom filter commands.
101101

102-
```cs
103-
bool[] res1 = db.BF().MAdd(
104-
"recorded_users", "andy", "cameron", "david", "michelle"
105-
);
106-
Console.WriteLine(string.Join(", ", res1));
107-
// >>> true, true, true, true
108-
109-
bool res2 = db.BF().Exists("recorded_users", "cameron");
110-
Console.WriteLine(res2); // >>> true
111-
112-
bool res3 = db.BF().Exists("recorded_users", "kaitlyn");
113-
Console.WriteLine(res3); // >>> false
114-
```
115-
<!--< clients-example home_prob_dts bloom "C#" >}}
116-
< /clients-example >}} -->
102+
{{< clients-example home_prob_dts bloom "C#" >}}
103+
{{< /clients-example >}}
117104

118105
A Cuckoo filter has similar features to a Bloom filter, but also supports
119106
a deletion operation to remove hashes from a set, as shown in the example
120107
below. Note that you must use the `CF()` method to access the Cuckoo filter
121108
commands.
122109

123-
```cs
124-
bool res4 = db.CF().Add("other_users", "paolo");
125-
Console.WriteLine(res4); // >>> true
126-
127-
bool res5 = db.CF().Add("other_users", "kaitlyn");
128-
Console.WriteLine(res5); // >>> true
129-
130-
bool res6 = db.CF().Add("other_users", "rachel");
131-
Console.WriteLine(res6); // >>> true
132-
133-
bool[] res7 = db.CF().MExists("other_users", "paolo", "rachel", "andy");
134-
Console.WriteLine(string.Join(", ", res7));
135-
// >>> true, true, false
136-
137-
bool res8 = db.CF().Del("other_users", "paolo");
138-
Console.WriteLine(res8); // >>> true
139-
140-
bool res9 = db.CF().Exists("other_users", "paolo");
141-
Console.WriteLine(res9); // >>> false
142-
```
143-
<!--< clients-example home_prob_dts cuckoo "C#" >}}
144-
< /clients-example >}} -->
110+
{{< clients-example home_prob_dts cuckoo "C#" >}}
111+
{{< /clients-example >}}
145112

146113
Which of these two data types you choose depends on your use case.
147114
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
161128
[union](https://en.wikipedia.org/wiki/Union_(set_theory)) of the sets they
162129
represent.
163130

164-
```cs
165-
bool res10 = db.HyperLogLogAdd(
166-
"group:1",
167-
new RedisValue[] { "andy", "cameron", "david" }
168-
);
169-
Console.WriteLine(res10); // >>> true
170-
171-
long res11 = db.HyperLogLogLength("group:1");
172-
Console.WriteLine(res11); // >>> 3
173-
174-
bool res12 = db.HyperLogLogAdd(
175-
"group:2",
176-
new RedisValue[] { "kaitlyn", "michelle", "paolo", "rachel" }
177-
);
178-
Console.WriteLine(res12); // >>> true
179-
180-
long res13 = db.HyperLogLogLength("group:2");
181-
Console.WriteLine(res13); // >>> 4
182-
183-
db.HyperLogLogMerge(
184-
"both_groups",
185-
"group:1", "group:2"
186-
);
187-
188-
long res14 = db.HyperLogLogLength("both_groups");
189-
Console.WriteLine(res14); // >>> 7
190-
```
191-
<!--< clients-example home_prob_dts hyperloglog "C#" >}}
192-
< /clients-example >}} -->
131+
{{< clients-example home_prob_dts hyperloglog "C#" >}}
132+
{{< /clients-example >}}
193133

194134
The main benefit that HyperLogLogs offer is their very low
195135
memory usage. They can count up to 2^64 items with less than
@@ -228,44 +168,9 @@ of going outside this limit. The example below shows how to create
228168
a Count-min sketch object, add data to it, and then query it.
229169
Note that you must use the `CMS()` method to access the Count-min
230170
sketch commands.
231-
```cs
232-
// Specify that you want to keep the counts within 0.01
233-
// (1%) of the true value with a 0.005 (0.5%) chance
234-
// of going outside this limit.
235-
bool res15 = db.CMS().InitByProb("items_sold", 0.01, 0.005);
236-
Console.WriteLine(res15); // >>> true
237-
238-
long[] res16 = db.CMS().IncrBy(
239-
"items_sold",
240-
new Tuple<RedisValue, long>[]{
241-
new("bread", 300),
242-
new("tea", 200),
243-
new("coffee", 200),
244-
new("beer", 100)
245-
}
246-
);
247-
Console.WriteLine(string.Join(", ", res16));
248-
// >>> 300, 200, 200, 100
249-
250-
long[] res17 = db.CMS().IncrBy(
251-
"items_sold",
252-
new Tuple<RedisValue, long>[]{
253-
new("bread", 100),
254-
new("coffee", 150),
255-
}
256-
);
257-
Console.WriteLine(string.Join(", ", res17));
258-
// >>> 400, 350
259-
260-
long[] res18 = db.CMS().Query(
261-
"items_sold",
262-
"bread", "tea", "coffee", "beer"
263-
);
264-
Console.WriteLine(string.Join(", ", res18));
265-
// >>> 400, 200, 350, 100
266-
```
267-
<!--< clients-example home_prob_dts cms "C#" >}}
268-
< /clients-example >}} -->
171+
172+
{{< clients-example home_prob_dts cms "C#" >}}
173+
{{< /clients-example >}}
269174

270175
The advantage of using a CMS over keeping an exact count with a
271176
[sorted set]({{< relref "/develop/data-types/sorted-sets" >}})
@@ -297,53 +202,8 @@ shows how to merge two or more t-digest objects to query the combined
297202
data set. Note that you must use the `TDIGEST()` method to access the
298203
t-digest commands.
299204

300-
```cs
301-
bool res19 = db.TDIGEST().Create("male_heights");
302-
Console.WriteLine(res19); // >>> true
303-
304-
bool res20 = db.TDIGEST().Add(
305-
"male_heights",
306-
175.5, 181, 160.8, 152, 177, 196, 164
307-
);
308-
Console.WriteLine(res20); // >>> true
309-
310-
double res21 = db.TDIGEST().Min("male_heights");
311-
Console.WriteLine(res21); // >>> 152.0
312-
313-
double res22 = db.TDIGEST().Max("male_heights");
314-
Console.WriteLine(res22); // >>> 196.0
315-
316-
double[] res23 = db.TDIGEST().Quantile("male_heights", 0.75);
317-
Console.WriteLine(string.Join(", ", res23)); // >>> 181.0
318-
319-
// Note that the CDF value for 181.0 is not exactly
320-
// 0.75. Both values are estimates.
321-
double[] res24 = db.TDIGEST().CDF("male_heights", 181.0);
322-
Console.WriteLine(string.Join(", ", res24)); // >>> 0.7857142857142857
323-
324-
bool res25 = db.TDIGEST().Create("female_heights");
325-
Console.WriteLine(res25); // >>> true
326-
327-
bool res26 = db.TDIGEST().Add(
328-
"female_heights",
329-
155.5, 161, 168.5, 170, 157.5, 163, 171
330-
);
331-
Console.WriteLine(res26); // >>> true
332-
333-
double[] res27 = db.TDIGEST().Quantile("female_heights", 0.75);
334-
Console.WriteLine(string.Join(", ", res27)); // >>> 170.0
335-
336-
// Specify 0 for `compression` and false for `override`.
337-
bool res28 = db.TDIGEST().Merge(
338-
"all_heights", 0, false, "male_heights", "female_heights"
339-
);
340-
Console.WriteLine(res28); // >>> true
341-
342-
double[] res29 = db.TDIGEST().Quantile("all_heights", 0.75);
343-
Console.WriteLine(string.Join(", ", res29)); // >>> 175.5
344-
```
345-
<!--< clients-example home_prob_dts tdigest "C#" >}}
346-
< /clients-example >}} -->
205+
{{< clients-example home_prob_dts tdigest "C#" >}}
206+
{{< /clients-example >}}
347207

348208
A t-digest object also supports several other related commands, such
349209
as querying by rank. See the
@@ -365,54 +225,5 @@ top *k* items and query whether or not a given item is in the
365225
list. Note that you must use the `TOPK()` method to access the
366226
Top-K commands.
367227

368-
```cs
369-
bool res30 = db.TOPK().Reserve("top_3_songs", 3, 7, 8, 0.9);
370-
Console.WriteLine(res30); // >>> true
371-
372-
RedisResult[] res31 = db.TOPK().IncrBy(
373-
"top_3_songs",
374-
new Tuple<RedisValue, long>[] {
375-
new("Starfish Trooper", 3000),
376-
new("Only one more time", 1850),
377-
new("Rock me, Handel", 1325),
378-
new("How will anyone know?", 3890),
379-
new("Average lover", 4098),
380-
new("Road to everywhere", 770)
381-
}
382-
);
383-
Console.WriteLine(
384-
string.Join(
385-
", ",
386-
string.Join(
387-
", ",
388-
res31.Select(
389-
r => $"{(r.IsNull ? "Null" : r)}"
390-
)
391-
)
392-
)
393-
);
394-
// >>> Null, Null, Null, Rock me, Handel, Only one more time, Null
395-
396-
RedisResult[] res32 = db.TOPK().List("top_3_songs");
397-
Console.WriteLine(
398-
string.Join(
399-
", ",
400-
string.Join(
401-
", ",
402-
res32.Select(
403-
r => $"{(r.IsNull ? "Null" : r)}"
404-
)
405-
)
406-
)
407-
);
408-
// >>> Average lover, How will anyone know?, Starfish Trooper
409-
410-
bool[] res33 = db.TOPK().Query(
411-
"top_3_songs",
412-
"Starfish Trooper", "Road to everywhere"
413-
);
414-
Console.WriteLine(string.Join(", ", res33));
415-
// >>> true, false
416-
```
417-
<!--< clients-example home_prob_dts topk "C#" >}}
418-
< /clients-example >}} -->
228+
{{< clients-example home_prob_dts topk "C#" >}}
229+
{{< /clients-example >}}

content/develop/clients/dotnet/transpipe.md

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,8 @@ versions of the standard command methods
3737
buffered in the pipeline and only execute when you call the `Execute()`
3838
method on the pipeline object.
3939

40-
```cs
41-
var pipeline = new Pipeline(db);
42-
43-
for (int i = 0; i < 5; i++)
44-
{
45-
pipeline.Db.StringSetAsync($"seat:{i}", $"#{i}");
46-
}
47-
pipeline.Execute();
48-
49-
var resp1 = db.StringGet("seat:0");
50-
Console.WriteLine(resp1); // >>> #0
51-
52-
var resp2 = db.StringGet("seat:3");
53-
Console.WriteLine(resp2); // >>> #3
54-
55-
var resp3 = db.StringGet("seat:4");
56-
Console.WriteLine(resp2); // >>> #4
57-
```
58-
<!--< clients-example pipe_trans_tutorial basic_pipe "C#" >}}
59-
< /clients-example >}} -->
40+
{{< clients-example pipe_trans_tutorial basic_pipe "C#" >}}
41+
{{< /clients-example >}}
6042

6143
## Execute a transaction
6244

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

68-
```cs
69-
var trans = new Transaction(db);
70-
71-
trans.Db.StringIncrementAsync("counter:1", 1);
72-
trans.Db.StringIncrementAsync("counter:2", 2);
73-
trans.Db.StringIncrementAsync("counter:3", 3);
74-
75-
trans.Execute();
76-
77-
var resp4 = db.StringGet("counter:1");
78-
Console.WriteLine(resp4); // >>> 1
79-
80-
var resp5 = db.StringGet("counter:2");
81-
Console.WriteLine(resp5); // >>> 2
82-
83-
var resp6 = db.StringGet("counter:3");
84-
Console.WriteLine(resp6); // >>> 3
85-
```
86-
<!--< clients-example pipe_trans_tutorial basic_trans "C#" >}}
87-
< /clients-example >}} -->
50+
{{< clients-example pipe_trans_tutorial basic_trans "C#" >}}
51+
{{< /clients-example >}}
8852

8953
## Watch keys for changes
9054

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

116-
```cs
117-
var watchedTrans = new Transaction(db);
118-
119-
watchedTrans.AddCondition(Condition.KeyNotExists("customer:39182"));
120-
121-
watchedTrans.Db.HashSetAsync(
122-
"customer:39182",
123-
new HashEntry[]{
124-
new HashEntry("name", "David"),
125-
new HashEntry("age", "27")
126-
}
127-
);
128-
129-
bool succeeded = watchedTrans.Execute();
130-
Console.WriteLine(succeeded); // >>> true
131-
```
132-
<!--< clients-example pipe_trans_tutorial trans_watch "C#" >}}
133-
< /clients-example >}} -->
80+
{{< clients-example pipe_trans_tutorial trans_watch "C#" >}}
81+
{{< /clients-example >}}
13482

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

0 commit comments

Comments
 (0)