File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ namespace NRedisStack.Tests
55{
66 public class RedisFixture : IDisposable
77 {
8+ private readonly IDatabase _db ; // TODO: Check if its right to have this here
9+
810 public RedisFixture ( ) => Redis = ConnectionMultiplexer . Connect ( "localhost" ) ;
911
1012 public void Dispose ( )
@@ -13,5 +15,25 @@ public void Dispose()
1315 }
1416
1517 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+ }
1638 }
1739}
You can’t perform that action at this time.
0 commit comments