Skip to content

Commit a13e2b2

Browse files
DOC-5501 C# trans/pipe examples
1 parent 23cc357 commit a13e2b2

File tree

1 file changed

+58
-6
lines changed

1 file changed

+58
-6
lines changed

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)