@@ -99,49 +99,16 @@ add. The following example adds some names to a Bloom filter representing
9999a list of users and checks for the presence or absence of users in the list.
100100Note 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 >}}-->
104- ``` cs
105- bool [] res1 = db .BF ().MAdd (
106- " recorded_users" , " andy" , " cameron" , " david" , " michelle"
107- );
108- Console .WriteLine (string .Join (" , " , res1 ));
109- // >>> true, true, true, true
110-
111- bool res2 = db .BF ().Exists (" recorded_users" , " cameron" );
112- Console .WriteLine (res2 ); // >>> true
113-
114- bool res3 = db .BF ().Exists (" recorded_users" , " kaitlyn" );
115- Console .WriteLine (res3 ); // >>> false
116- ```
102+ {{< clients-example home_prob_dts bloom "C#" >}}
103+ {{< /clients-example >}}
117104
118105A Cuckoo filter has similar features to a Bloom filter, but also supports
119106a deletion operation to remove hashes from a set, as shown in the example
120107below. Note that you must use the ` CF() ` method to access the Cuckoo filter
121108commands.
122109
123- <!-- < clients-example home_prob_dts cuckoo "C#" >}}
124- < /clients-example >}}-->
125- ``` cs
126- bool res4 = db .CF ().Add (" other_users" , " paolo" );
127- Console .WriteLine (res4 ); // >>> true
128-
129- bool res5 = db .CF ().Add (" other_users" , " kaitlyn" );
130- Console .WriteLine (res5 ); // >>> true
131-
132- bool res6 = db .CF ().Add (" other_users" , " rachel" );
133- Console .WriteLine (res6 ); // >>> true
134-
135- bool [] res7 = db .CF ().MExists (" other_users" , " paolo" , " rachel" , " andy" );
136- Console .WriteLine (string .Join (" , " , res7 ));
137- // >>> true, true, false
138-
139- bool res8 = db .CF ().Del (" other_users" , " paolo" );
140- Console .WriteLine (res8 ); // >>> true
141-
142- bool res9 = db .CF ().Exists (" other_users" , " paolo" );
143- Console .WriteLine (res9 ); // >>> false
144- ```
110+ {{< clients-example home_prob_dts cuckoo "C#" >}}
111+ {{< /clients-example >}}
145112
146113Which of these two data types you choose depends on your use case.
147114Bloom 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
162129represent.
163130
164- <!-- < clients-example home_prob_dts hyperloglog "C#" >}}
165- < /clients-example >}}-->
166- ``` cs
167- bool res10 = db .HyperLogLogAdd (
168- " group:1" ,
169- new RedisValue [] { " andy" , " cameron" , " david" }
170- );
171- Console .WriteLine (res10 ); // >>> true
172-
173- long res11 = db .HyperLogLogLength (" group:1" );
174- Console .WriteLine (res11 ); // >>> 3
175-
176- bool res12 = db .HyperLogLogAdd (
177- " group:2" ,
178- new RedisValue [] { " kaitlyn" , " michelle" , " paolo" , " rachel" }
179- );
180- Console .WriteLine (res12 ); // >>> true
181-
182- long res13 = db .HyperLogLogLength (" group:2" );
183- Console .WriteLine (res13 ); // >>> 4
184-
185- db .HyperLogLogMerge (
186- " both_groups" ,
187- " group:1" , " group:2"
188- );
189-
190- long res14 = db .HyperLogLogLength (" both_groups" );
191- Console .WriteLine (res14 ); // >>> 7
192- ```
131+ {{< clients-example home_prob_dts hyperloglog "C#" >}}
132+ {{< /clients-example >}}
193133
194134The main benefit that HyperLogLogs offer is their very low
195135memory 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.
229169Note that you must use the ` CMS() ` method to access the Count-min
230170sketch commands.
231171
232- <!-- < clients-example home_prob_dts cms "C#" >}}
233- < /clients-example >}}-->
234- ``` cs
235- // Specify that you want to keep the counts within 0.01
236- // (1%) of the true value with a 0.005 (0.5%) chance
237- // of going outside this limit.
238- bool res15 = db .CMS ().InitByProb (" items_sold" , 0 . 01 , 0 . 005 );
239- Console .WriteLine (res15 ); // >>> true
240-
241- long [] res16 = db .CMS ().IncrBy (
242- " items_sold" ,
243- new Tuple <RedisValue , long >[]{
244- new (" bread" , 300 ),
245- new (" tea" , 200 ),
246- new (" coffee" , 200 ),
247- new (" beer" , 100 )
248- }
249- );
250- Console .WriteLine (string .Join (" , " , res16 ));
251- // >>> 300, 200, 200, 100
252-
253- long [] res17 = db .CMS ().IncrBy (
254- " items_sold" ,
255- new Tuple <RedisValue , long >[]{
256- new (" bread" , 100 ),
257- new (" coffee" , 150 ),
258- }
259- );
260- Console .WriteLine (string .Join (" , " , res17 ));
261- // >>> 400, 350
262-
263- long [] res18 = db .CMS ().Query (
264- " items_sold" ,
265- " bread" , " tea" , " coffee" , " beer"
266- );
267- Console .WriteLine (string .Join (" , " , res18 ));
268- // >>> 400, 200, 350, 100
269- ```
172+ {{< clients-example home_prob_dts cms "C#" >}}
173+ {{< /clients-example >}}
270174
271175The advantage of using a CMS over keeping an exact count with a
272176[ 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
298202data set. Note that you must use the ` TDIGEST() ` method to access the
299203t-digest commands.
300204
301- <!-- < clients-example home_prob_dts tdigest "C#" >}}
302- < /clients-example >}}-->
303- ``` cs
304- bool res19 = db .TDIGEST ().Create (" male_heights" );
305- Console .WriteLine (res19 ); // >>> true
306-
307- bool res20 = db .TDIGEST ().Add (
308- " male_heights" ,
309- 175 . 5 , 181 , 160 . 8 , 152 , 177 , 196 , 164
310- );
311- Console .WriteLine (res20 ); // >>> true
312-
313- double res21 = db .TDIGEST ().Min (" male_heights" );
314- Console .WriteLine (res21 ); // >>> 152.0
315-
316- double res22 = db .TDIGEST ().Max (" male_heights" );
317- Console .WriteLine (res22 ); // >>> 196.0
318-
319- double [] res23 = db .TDIGEST ().Quantile (" male_heights" , 0 . 75 );
320- Console .WriteLine (string .Join (" , " , res23 )); // >>> 181.0
321-
322- // Note that the CDF value for 181.0 is not exactly
323- // 0.75. Both values are estimates.
324- double [] res24 = db .TDIGEST ().CDF (" male_heights" , 181 . 0 );
325- Console .WriteLine (string .Join (" , " , res24 )); // >>> 0.7857142857142857
326-
327- bool res25 = db .TDIGEST ().Create (" female_heights" );
328- Console .WriteLine (res25 ); // >>> true
329-
330- bool res26 = db .TDIGEST ().Add (
331- " female_heights" ,
332- 155 . 5 , 161 , 168 . 5 , 170 , 157 . 5 , 163 , 171
333- );
334- Console .WriteLine (res26 ); // >>> true
335-
336- double [] res27 = db .TDIGEST ().Quantile (" female_heights" , 0 . 75 );
337- Console .WriteLine (string .Join (" , " , res27 )); // >>> 170.0
338-
339- // Specify 0 for `compression` and false for `override`.
340- bool res28 = db .TDIGEST ().Merge (
341- " all_heights" , 0 , false , " male_heights" , " female_heights"
342- );
343- Console .WriteLine (res28 ); // >>> true
344-
345- double [] res29 = db .TDIGEST ().Quantile (" all_heights" , 0 . 75 );
346- Console .WriteLine (string .Join (" , " , res29 )); // >>> 175.5
347- ```
205+ {{< clients-example home_prob_dts tdigest "C#" >}}
206+ {{< /clients-example >}}
348207
349208A t-digest object also supports several other related commands, such
350209as querying by rank. See the
@@ -366,54 +225,5 @@ top *k* items and query whether or not a given item is in the
366225list. Note that you must use the ` TOPK() ` method to access the
367226Top-K commands.
368227
369- <!-- < clients-example home_prob_dts topk "C#" >}}
370- < /clients-example >}}-->
371- ``` cs
372- bool res30 = db .TOPK ().Reserve (" top_3_songs" , 3 , 7 , 8 , 0 . 9 );
373- Console .WriteLine (res30 ); // >>> true
374-
375- RedisResult [] res31 = db .TOPK ().IncrBy (
376- " top_3_songs" ,
377- new Tuple <RedisValue , long >[] {
378- new (" Starfish Trooper" , 3000 ),
379- new (" Only one more time" , 1850 ),
380- new (" Rock me, Handel" , 1325 ),
381- new (" How will anyone know?" , 3890 ),
382- new (" Average lover" , 4098 ),
383- new (" Road to everywhere" , 770 )
384- }
385- );
386- Console .WriteLine (
387- string .Join (
388- " , " ,
389- string .Join (
390- " , " ,
391- res31 .Select (
392- r => $" {(r .IsNull ? " Null" : r )}"
393- )
394- )
395- )
396- );
397- // >>> Null, Null, Null, Rock me, Handel, Only one more time, Null
398-
399- RedisResult [] res32 = db .TOPK ().List (" top_3_songs" );
400- Console .WriteLine (
401- string .Join (
402- " , " ,
403- string .Join (
404- " , " ,
405- res32 .Select (
406- r => $" {(r .IsNull ? " Null" : r )}"
407- )
408- )
409- )
410- );
411- // >>> Average lover, How will anyone know?, Starfish Trooper
412-
413- bool [] res33 = db .TOPK ().Query (
414- " top_3_songs" ,
415- " Starfish Trooper" , " Road to everywhere"
416- );
417- Console .WriteLine (string .Join (" , " , res33 ));
418- // >>> true, false
419- ```
228+ {{< clients-example home_prob_dts topk "C#" >}}
229+ {{< /clients-example >}}
0 commit comments