@@ -37,8 +37,26 @@ versions of the standard command methods
37
37
buffered in the pipeline and only execute when you call the ` Execute() `
38
38
method on the pipeline object.
39
39
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 >}} -->
42
60
43
61
## Execute a transaction
44
62
@@ -47,8 +65,26 @@ instance of the `Transaction` class, call async command methods
47
65
on that object, and then call the transaction object's
48
66
` Execute() ` method to execute it.
49
67
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 >}} -->
52
88
53
89
## Watch keys for changes
54
90
@@ -77,8 +113,24 @@ For example, the `KeyNotExists` condition aborts the transaction
77
113
if a specified key exists or is added by another client while the
78
114
transaction executes:
79
115
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 >}} -->
82
134
83
135
You can also use a ` When ` condition on certain individual commands to
84
136
specify that they only execute when a certain condition holds
0 commit comments