Skip to content

Commit b196040

Browse files
committed
Async Example
1 parent 1f0e002 commit b196040

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Examples/AsyncExample.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# Async Example
3+
4+
## All methods have synchronous & asynchronous implementation. the asynchronous methods all end ...Async(...), and are fully await-able. here is an example of using the async methods:
5+
6+
### Connect to the Redis server and get a reference to the database and for JSON commands:
7+
8+
```csharp
9+
var redis = await ConnectionMultiplexer.ConnectAsync("localhost");
10+
var db = redis.GetDatabase();
11+
var json = db.JSON();
12+
```
13+
14+
### call async version of JSON.SET/GET
15+
16+
```csharp
17+
await json.SetAsync("key", "$", new { name = "John", age = 30, city = "New York" });
18+
var john = await json.GetAsync("key");
19+
```

tests/NRedisStack.Tests/Examples/ExamplesTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,17 @@ public void HSETandSearch()
6060
var lastNameRod = ft.Search("example_index", new Query("@last:Rod"));
6161
// lastNameRod is empty because there are no hashes with a last name of Rod that match the index definition
6262
}
63+
64+
[Fact]
65+
public async Task AsyncExample()
66+
{
67+
// Connect to the Redis server
68+
var redis = await ConnectionMultiplexer.ConnectAsync("localhost");
69+
var db = redis.GetDatabase();
70+
var json = db.JSON();
71+
72+
// call async version of JSON.SET/GET
73+
await json.SetAsync("key", "$", new { name = "John", age = 30, city = "New York" });
74+
var john = await json.GetAsync("key");
75+
}
6376
}

0 commit comments

Comments
 (0)