Skip to content

Commit bfb9d0b

Browse files
Merge pull request #1880 from redis/DOC-5501-temp-non-tce-examples
DOC-5501 temporary non-TCE examples
2 parents bfc8ce3 + 7ac10a7 commit bfb9d0b

File tree

4 files changed

+606
-43
lines changed

4 files changed

+606
-43
lines changed

content/develop/clients/dotnet/prob.md

Lines changed: 202 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,49 @@ 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-
{{< clients-example home_prob_dts bloom "C#" >}}
103-
{{< /clients-example >}}
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 >}} -->
104117

105118
A Cuckoo filter has similar features to a Bloom filter, but also supports
106119
a deletion operation to remove hashes from a set, as shown in the example
107120
below. Note that you must use the `CF()` method to access the Cuckoo filter
108121
commands.
109122

110-
{{< clients-example home_prob_dts cuckoo "C#" >}}
111-
{{< /clients-example >}}
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 >}} -->
112145

113146
Which of these two data types you choose depends on your use case.
114147
Bloom filters are generally faster than Cuckoo filters when adding new items,
@@ -128,8 +161,35 @@ You can also merge two or more HyperLogLogs to find the cardinality of the
128161
[union](https://en.wikipedia.org/wiki/Union_(set_theory)) of the sets they
129162
represent.
130163

131-
{{< clients-example home_prob_dts hyperloglog "C#" >}}
132-
{{< /clients-example >}}
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 >}} -->
133193

134194
The main benefit that HyperLogLogs offer is their very low
135195
memory usage. They can count up to 2^64 items with less than
@@ -168,9 +228,44 @@ of going outside this limit. The example below shows how to create
168228
a Count-min sketch object, add data to it, and then query it.
169229
Note that you must use the `CMS()` method to access the Count-min
170230
sketch commands.
171-
172-
{{< clients-example home_prob_dts cms "C#" >}}
173-
{{< /clients-example >}}
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 >}} -->
174269

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

205-
{{< clients-example home_prob_dts tdigest "C#" >}}
206-
{{< /clients-example >}}
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 >}} -->
207347

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

228-
{{< clients-example home_prob_dts topk "C#" >}}
229-
{{< /clients-example >}}
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 >}} -->

content/develop/clients/dotnet/transpipe.md

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,26 @@ 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-
{{< clients-example pipe_trans_tutorial basic_pipe "C#" >}}
41-
{{< /clients-example >}}
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 >}} -->
4260

4361
## Execute a transaction
4462

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

50-
{{< clients-example pipe_trans_tutorial basic_trans "C#" >}}
51-
{{< /clients-example >}}
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 >}} -->
5288

5389
## Watch keys for changes
5490

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

80-
{{< clients-example pipe_trans_tutorial trans_watch "C#" >}}
81-
{{< /clients-example >}}
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 >}} -->
82134

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

0 commit comments

Comments
 (0)