Skip to content

Commit ce15773

Browse files
Merge pull request #2188 from redis/DOC-5769-csharp-async
DOC-5769 C# async TCE support
2 parents c28793b + d2d9f46 commit ce15773

File tree

13 files changed

+192
-56
lines changed

13 files changed

+192
-56
lines changed

build/components/example.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
'java-sync': '@Test',
1515
'java-async': '@Test',
1616
'java-reactive': '@Test',
17-
'c#': r'\[Fact]|\[SkipIfRedis\(.*\)]'
17+
'c#': r'\[Fact]|\[SkipIfRedis\(.*\)]',
18+
'c#-sync': r'\[Fact]|\[SkipIfRedis\(.*\)]',
19+
'c#-async': r'\[Fact]|\[SkipIfRedis\(.*\)]'
1820
}
1921
PREFIXES = {
2022
'python': '#',
@@ -25,6 +27,8 @@
2527
'java-reactive': '//',
2628
'go': '//',
2729
'c#': '//',
30+
'c#-sync': '//',
31+
'c#-async': '//',
2832
'redisvl': '#',
2933
'php': '//',
3034
'rust': '//',

build/local_examples.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'python': 'Python',
3535
'node.js': 'Node.js',
3636
'go': 'Go',
37-
'c#': 'C#',
37+
'c#': 'C#-Sync',
3838
'java': 'Java-Sync', # Default to sync, could be overridden
3939
'php': 'PHP',
4040
'redisvl': 'RedisVL',
@@ -72,6 +72,11 @@ def get_client_name_from_language_and_path(language: str, path: str) -> str:
7272
return 'Rust-Async'
7373
if 'rust-sync' in path:
7474
return 'Rust-Sync'
75+
if language == 'c#':
76+
if 'async' in path:
77+
return 'C#-Async'
78+
if 'sync' in path:
79+
return 'C#-Sync'
7580
# Default behavior for all languages (and Java fallback)
7681
return get_client_name_from_language(language)
7782

config.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ tagManagerId = "GTM-TKZ6J9R"
4545
gitHubRepo = "https://github.com/redis/docs"
4646

4747
# Display and sort order for client examples
48-
clientsExamples = ["Python", "Node.js", "Java-Sync", "Java-Async", "Java-Reactive", "Go", "C#", "RedisVL", "PHP", "Rust-Sync", "Rust-Async"]
48+
clientsExamples = ["Python", "Node.js", "Java-Sync", "Java-Async", "Java-Reactive", "Go", "C#-Sync", "C#-Async", "RedisVL", "PHP", "Rust-Sync", "Rust-Async"]
4949
searchService = "/convai/api/search-service"
5050
ratingsService = "/docusight/api/rate"
5151

@@ -64,7 +64,8 @@ rdi_current_version = "1.14.1"
6464
"Java-async"={quickstartSlug="lettuce"}
6565
"Java-reactive"={quickstartSlug="lettuce"}
6666
"Go"={quickstartSlug="go"}
67-
"C#"={quickstartSlug="dotnet"}
67+
"C#-Sync"={quickstartSlug="dotnet"}
68+
"C#-Async"={quickstartSlug="dotnet"}
6869
"RedisVL"={quickstartSlug="redis-vl"}
6970
"PHP"={quickstartSlug="php"}
7071
"Rust-sync"={quickstartSlug="rust"}

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

content/develop/clients/dotnet/vecsets.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@ dotnet add package Microsoft.ML
4848
In a new C# file, import the required classes. Note that the `#pragma`
4949
directive suppresses warnings about the experimental status of the vector set API:
5050

51-
{{< clients-example set="home_vecsets" step="import" lang_filter="C#" >}}
51+
{{< clients-example set="home_vecsets" step="import" lang_filter="C#-Sync" >}}
5252
{{< /clients-example >}}
5353

5454
## Access the model
5555

5656
Use the `GetPredictionEngine()` helper function declared in the example below to load the model that creates the embeddings:
5757

58-
{{< clients-example set="home_vecsets" step="model" lang_filter="C#" >}}
58+
{{< clients-example set="home_vecsets" step="model" lang_filter="C#-Sync" >}}
5959
{{< /clients-example >}}
6060

6161
The `GetPredictionEngine()` function uses two classes, `TextData` and `TransformedTextData`,
6262
to specify the `PredictionEngine` model. These have a very simple definition
6363
and are required because the model expects the input and output to be
6464
passed in named object fields:
6565

66-
{{< clients-example set="home_vecsets" step="data_classes" lang_filter="C#" >}}
66+
{{< clients-example set="home_vecsets" step="data_classes" lang_filter="C#-Sync" >}}
6767
{{< /clients-example >}}
6868

6969
Note that you must declare these classes at the end of the source file
@@ -73,15 +73,15 @@ The `GetEmbedding()` function declared below can then use this model to
7373
generate an embedding from a section of text and return it as a `float[]` array,
7474
which is the format required by the vector set API:
7575

76-
{{< clients-example set="home_vecsets" step="get_embedding" lang_filter="C#" >}}
76+
{{< clients-example set="home_vecsets" step="get_embedding" lang_filter="C#-Sync" >}}
7777
{{< /clients-example >}}
7878

7979
## Create the data
8080

8181
The example data is contained a `Dictionary` object with some brief
8282
descriptions of famous people:
8383

84-
{{< clients-example set="home_vecsets" step="data" lang_filter="C#" >}}
84+
{{< clients-example set="home_vecsets" step="data" lang_filter="C#-Sync" >}}
8585
{{< /clients-example >}}
8686

8787
## Add the data to a vector set
@@ -99,7 +99,7 @@ The call to `VectorSetAdd()` also adds the `born` and `died` values from the
9999
original dictionary as attribute data. You can access this during a query
100100
or by using the [`VectorSetGetAttributesJson()`]({{< relref "/commands/vgetattr" >}}) method.
101101

102-
{{< clients-example set="home_vecsets" step="add_data" lang_filter="C#" >}}
102+
{{< clients-example set="home_vecsets" step="add_data" lang_filter="C#-Sync" >}}
103103
{{< /clients-example >}}
104104

105105
## Query the vector set
@@ -112,7 +112,7 @@ return elements of the set, ranked in order of similarity to the query.
112112

113113
Start with a simple query for "actors":
114114

115-
{{< clients-example set="home_vecsets" step="basic_query" lang_filter="C#" >}}
115+
{{< clients-example set="home_vecsets" step="basic_query" lang_filter="C#-Sync" >}}
116116
{{< /clients-example >}}
117117

118118
This returns the following list of elements (formatted slightly for clarity):
@@ -131,7 +131,7 @@ on the information contained in the embedding model.
131131
You can use the `Count` property of `VectorSetSimilaritySearchRequest` to limit the
132132
list of elements to just the most relevant few items:
133133

134-
{{< clients-example set="home_vecsets" step="limited_query" lang_filter="C#" >}}
134+
{{< clients-example set="home_vecsets" step="limited_query" lang_filter="C#-Sync" >}}
135135
{{< /clients-example >}}
136136

137137
The reason for using text embeddings rather than simple text search
@@ -141,7 +141,7 @@ different. For example, the word "entertainer" doesn't appear in any of the
141141
descriptions but if you use it as a query, the actors and musicians are ranked
142142
highest in the results list:
143143

144-
{{< clients-example set="home_vecsets" step="entertainer_query" lang_filter="C#" >}}
144+
{{< clients-example set="home_vecsets" step="entertainer_query" lang_filter="C#-Sync" >}}
145145
{{< /clients-example >}}
146146

147147
Similarly, if you use "science" as a query, you get the following results:
@@ -162,7 +162,7 @@ with `VectorSetSimilaritySearch()` to restrict the search further. For example,
162162
repeat the "science" query, but this time limit the results to people
163163
who died before the year 2000:
164164

165-
{{< clients-example set="home_vecsets" step="filtered_query" lang_filter="C#" >}}
165+
{{< clients-example set="home_vecsets" step="filtered_query" lang_filter="C#-Sync" >}}
166166
{{< /clients-example >}}
167167

168168
Note that the boolean filter expression is applied to items in the list

data/components/index.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"docs": [],
88
"modules": [],
99
"clients": [
10-
"nredisstack",
10+
"nredisstack_sync",
11+
"nredisstack_async",
1112
"go_redis",
1213
"node_redis",
1314
"php",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"id": "nredisstack_async",
3+
"type": "client",
4+
"name": "NRedisStack_Async",
5+
"language": "C#",
6+
"label": "C#-Async",
7+
"repository": {
8+
"git_uri": "https://github.com/redis/NRedisStack"
9+
},
10+
"examples": {
11+
"git_uri": "https://github.com/redis/NRedisStack",
12+
"path": "tests/Doc/Async",
13+
"pattern": "*.cs"
14+
}
15+
}

data/components/nredisstack.json renamed to data/components/nredisstack_sync.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"id": "nredisstack",
2+
"id": "nredisstack_sync",
33
"type": "client",
4-
"name": "NRedisStack",
4+
"name": "NRedisStack_Sync",
55
"language": "C#",
6-
"label": "C#",
6+
"label": "C#-Sync",
77
"repository": {
88
"git_uri": "https://github.com/redis/NRedisStack"
99
},

0 commit comments

Comments
 (0)