File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ namespace NRedisStack.Tests
5
5
{
6
6
public class RedisFixture : IDisposable
7
7
{
8
+ private readonly IDatabase _db ; // TODO: Check if its right to have this here
9
+
8
10
public RedisFixture ( ) => Redis = ConnectionMultiplexer . Connect ( "localhost" ) ;
9
11
10
12
public void Dispose ( )
@@ -13,5 +15,25 @@ public void Dispose()
13
15
}
14
16
15
17
public ConnectionMultiplexer Redis { get ; private set ; }
18
+
19
+ /// <summary>
20
+ /// Executes the contained commands within the context of a transaction.
21
+ /// </summary>
22
+ /// <param name="commandArgsTuples">each tuple represents a command and
23
+ /// it's arguments to execute inside a transaction.</param>
24
+ /// <returns>A RedisResult.</returns>
25
+ public RedisResult [ ] ExecuteInTransaction ( Tuple < string , string [ ] > [ ] commandArgsTuples )
26
+ {
27
+ var transaction = _db . CreateTransaction ( ) ;
28
+ var tasks = new List < Task < RedisResult > > ( ) ;
29
+ foreach ( var tuple in commandArgsTuples )
30
+ {
31
+ tasks . Add ( transaction . ExecuteAsync ( tuple . Item1 , tuple . Item2 ) ) ;
32
+ }
33
+
34
+ transaction . Execute ( ) ;
35
+ Task . WhenAll ( tasks ) . Wait ( ) ;
36
+ return tasks . Select ( x => x . Result ) . ToArray ( ) ;
37
+ }
16
38
}
17
39
}
You can’t perform that action at this time.
0 commit comments