Skip to content

Commit d2d9f46

Browse files
DOC-5769 fixed content to add basic async examples and fix client name
1 parent b7c9a0a commit d2d9f46

File tree

5 files changed

+148
-38
lines changed

5 files changed

+148
-38
lines changed

content/develop/clients/dotnet/_index.md

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,45 +36,31 @@ dotnet add package NRedisStack
3636

3737
## Connect and test
3838

39-
Connect to localhost on port 6379.
40-
41-
```csharp
42-
using NRedisStack;
43-
using NRedisStack.RedisStackCommands;
44-
using StackExchange.Redis;
45-
//...
46-
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
47-
IDatabase db = redis.GetDatabase();
48-
```
39+
Add the following imports to your source file:
40+
41+
{{< clients-example set="landing" step="import" lang_filter="C#-Sync,C#-Async" >}}
42+
{{< /clients-example >}}
43+
44+
Connect to localhost on port 6379. The client supports both synchronous and asynchronous commands.
45+
46+
{{< clients-example set="landing" step="connect" lang_filter="C#-Sync,C#-Async" >}}
47+
{{< /clients-example >}}
4948

5049
You can test the connection by storing and retrieving a simple string.
5150

52-
```csharp
53-
db.StringSet("foo", "bar");
54-
Console.WriteLine(db.StringGet("foo")); // prints bar
55-
```
51+
{{< clients-example set="landing" step="set_get_string" lang_filter="C#-Sync,C#-Async" >}}
52+
{{< /clients-example >}}
5653

5754
Store and retrieve a HashMap.
5855

59-
```csharp
60-
var hash = new HashEntry[] {
61-
new HashEntry("name", "John"),
62-
new HashEntry("surname", "Smith"),
63-
new HashEntry("company", "Redis"),
64-
new HashEntry("age", "29"),
65-
};
66-
db.HashSet("user-session:123", hash);
67-
68-
var hashFields = db.HashGetAll("user-session:123");
69-
Console.WriteLine(String.Join("; ", hashFields));
70-
// Prints:
71-
// name: John; surname: Smith; company: Redis; age: 29
72-
```
56+
{{< clients-example set="landing" step="set_get_hash" lang_filter="C#-Sync,C#-Async" >}}
57+
{{< /clients-example >}}
58+
7359
## Redis Open Source modules
7460

7561
To access Redis Open Source capabilities, use the appropriate interface like this:
7662

77-
```
63+
```cs
7864
IBloomCommands bf = db.BF();
7965
ICuckooCommands cf = db.CF();
8066
ICmsCommands cms = db.CMS();

content/develop/clients/dotnet/prob.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ 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#" >}}
102+
{{< clients-example home_prob_dts bloom "C#-Sync" >}}
103103
{{< /clients-example >}}
104104

105105
A Cuckoo filter has similar features to a Bloom filter, but also supports
106106
a deletion operation to remove hashes from a set, as shown in the example
107107
below. Note that you must use the `CF()` method to access the Cuckoo filter
108108
commands.
109109

110-
{{< clients-example home_prob_dts cuckoo "C#" >}}
110+
{{< clients-example home_prob_dts cuckoo "C#-Sync" >}}
111111
{{< /clients-example >}}
112112

113113
Which of these two data types you choose depends on your use case.
@@ -128,7 +128,7 @@ You can also merge two or more HyperLogLogs to find the cardinality of the
128128
[union](https://en.wikipedia.org/wiki/Union_(set_theory)) of the sets they
129129
represent.
130130

131-
{{< clients-example home_prob_dts hyperloglog "C#" >}}
131+
{{< clients-example home_prob_dts hyperloglog "C#-Sync" >}}
132132
{{< /clients-example >}}
133133

134134
The main benefit that HyperLogLogs offer is their very low
@@ -169,7 +169,7 @@ a Count-min sketch object, add data to it, and then query it.
169169
Note that you must use the `CMS()` method to access the Count-min
170170
sketch commands.
171171

172-
{{< clients-example home_prob_dts cms "C#" >}}
172+
{{< clients-example home_prob_dts cms "C#-Sync" >}}
173173
{{< /clients-example >}}
174174

175175
The advantage of using a CMS over keeping an exact count with a
@@ -202,7 +202,7 @@ shows how to merge two or more t-digest objects to query the combined
202202
data set. Note that you must use the `TDIGEST()` method to access the
203203
t-digest commands.
204204

205-
{{< clients-example home_prob_dts tdigest "C#" >}}
205+
{{< clients-example home_prob_dts tdigest "C#-Sync" >}}
206206
{{< /clients-example >}}
207207

208208
A t-digest object also supports several other related commands, such
@@ -225,5 +225,5 @@ top *k* items and query whether or not a given item is in the
225225
list. Note that you must use the `TOPK()` method to access the
226226
Top-K commands.
227227

228-
{{< clients-example home_prob_dts topk "C#" >}}
228+
{{< clients-example home_prob_dts topk "C#-Sync" >}}
229229
{{< /clients-example >}}

content/develop/clients/dotnet/transpipe.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ 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#" >}}
40+
{{< clients-example pipe_trans_tutorial basic_pipe "C#-Sync" >}}
4141
{{< /clients-example >}}
4242

4343
## Execute a transaction
@@ -47,7 +47,7 @@ instance of the `Transaction` class, call async command methods
4747
on that object, and then call the transaction object's
4848
`Execute()` method to execute it.
4949

50-
{{< clients-example pipe_trans_tutorial basic_trans "C#" >}}
50+
{{< clients-example pipe_trans_tutorial basic_trans "C#-Sync" >}}
5151
{{< /clients-example >}}
5252

5353
## Watch keys for changes
@@ -77,7 +77,7 @@ For example, the `KeyNotExists` condition aborts the transaction
7777
if a specified key exists or is added by another client while the
7878
transaction executes:
7979

80-
{{< clients-example pipe_trans_tutorial trans_watch "C#" >}}
80+
{{< clients-example pipe_trans_tutorial trans_watch "C#-Sync" >}}
8181
{{< /clients-example >}}
8282

8383
You can also use a `When` condition on certain individual commands to
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// EXAMPLE: landing
2+
// STEP_START import
3+
using NRedisStack;
4+
using NRedisStack.RedisStackCommands;
5+
using StackExchange.Redis;
6+
// STEP_END
7+
// REMOVE_START
8+
using NRedisStack.Tests;
9+
using System.Threading.Tasks;
10+
11+
namespace Doc;
12+
13+
[Collection("DocsTests")]
14+
// REMOVE_END
15+
16+
public class AsyncLandingExample
17+
// REMOVE_START
18+
: AbstractNRedisStackTest, IDisposable
19+
// REMOVE_END
20+
{
21+
// REMOVE_START
22+
public AsyncLandingExample(EndpointsFixture fixture) : base(fixture) { }
23+
24+
[SkippableFact]
25+
// REMOVE_END
26+
public async Task Run()
27+
{
28+
//REMOVE_START
29+
// This is needed because we're constructing ConfigurationOptions in the test before calling GetConnection
30+
SkipIfTargetConnectionDoesNotExist(EndpointsFixture.Env.Standalone);
31+
var _ = GetCleanDatabase(EndpointsFixture.Env.Standalone);
32+
//REMOVE_END
33+
// STEP_START connect
34+
var muxer = await ConnectionMultiplexer.ConnectAsync("localhost:6379");
35+
var db = muxer.GetDatabase();
36+
// STEP_END
37+
//REMOVE_START
38+
// Clear any keys here before using them in tests.
39+
await db.KeyDeleteAsync(new RedisKey[] { "bike:1", "foo", "user-session:123" });
40+
//REMOVE_END
41+
42+
// STEP_START set_get_string
43+
await db.StringSetAsync("foo", "bar");
44+
string? fooResult = await db.StringGetAsync("foo");
45+
Console.WriteLine(fooResult); // >>> bar
46+
// STEP_END
47+
48+
// STEP_START set_get_hash
49+
var hash = new HashEntry[] {
50+
new HashEntry("name", "John"),
51+
new HashEntry("surname", "Smith"),
52+
new HashEntry("company", "Redis"),
53+
new HashEntry("age", "29"),
54+
};
55+
await db.HashSetAsync("user-session:123", hash);
56+
57+
var hashFields = await db.HashGetAllAsync("user-session:123");
58+
Console.WriteLine(String.Join("; ", hashFields));
59+
// >>> name: John; surname: Smith; company: Redis; age: 29
60+
// STEP_END
61+
}
62+
}
63+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// EXAMPLE: landing
2+
// STEP_START import
3+
using NRedisStack;
4+
using NRedisStack.RedisStackCommands;
5+
using StackExchange.Redis;
6+
// STEP_END
7+
// REMOVE_START
8+
using NRedisStack.Tests;
9+
10+
namespace Doc;
11+
12+
[Collection("DocsTests")]
13+
// REMOVE_END
14+
15+
public class SyncLandingExample
16+
// REMOVE_START
17+
: AbstractNRedisStackTest, IDisposable
18+
// REMOVE_END
19+
{
20+
// REMOVE_START
21+
public SyncLandingExample(EndpointsFixture fixture) : base(fixture) { }
22+
23+
[SkippableFact]
24+
// REMOVE_END
25+
public void Run()
26+
{
27+
//REMOVE_START
28+
// This is needed because we're constructing ConfigurationOptions in the test before calling GetConnection
29+
SkipIfTargetConnectionDoesNotExist(EndpointsFixture.Env.Standalone);
30+
var _ = GetCleanDatabase(EndpointsFixture.Env.Standalone);
31+
//REMOVE_END
32+
// STEP_START connect
33+
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
34+
var db = muxer.GetDatabase();
35+
// STEP_END
36+
//REMOVE_START
37+
// Clear any keys here before using them in tests.
38+
db.KeyDelete(new RedisKey[] { "bike:1", "foo", "user-session:123" });
39+
//REMOVE_END
40+
41+
// STEP_START set_get_string
42+
db.StringSet("foo", "bar");
43+
Console.WriteLine(db.StringGet("foo")); // >>> bar
44+
// STEP_END
45+
46+
// STEP_START set_get_hash
47+
var hash = new HashEntry[] {
48+
new HashEntry("name", "John"),
49+
new HashEntry("surname", "Smith"),
50+
new HashEntry("company", "Redis"),
51+
new HashEntry("age", "29"),
52+
};
53+
db.HashSet("user-session:123", hash);
54+
55+
var hashFields = db.HashGetAll("user-session:123");
56+
Console.WriteLine(String.Join("; ", hashFields));
57+
// >>> name: John; surname: Smith; company: Redis; age: 29
58+
// STEP_END
59+
}
60+
}
61+

0 commit comments

Comments
 (0)