-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
URGENT Fix error in batch/transaction handling (#2177)
* PrepareScript should work for parameterless scripts; fix #2164 * update link in release notes * tyop * Batch/Transaction need to override new ExecuteAsync API; fix #2167 fix #2176 * Maintain correctness on NRTs and asyncState Previously the F+F case was getting a null default rather than the pass default value - this corrects that as well. It is not DRY across classes, but let's get this fix in ASAP then address that. * test both batch and transaction * bump Co-authored-by: Nick Craver <[email protected]>
- Loading branch information
1 parent
bc0c5a2
commit 0ebe530
Showing
4 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace StackExchange.Redis.Tests.Issues | ||
{ | ||
public class Issue2176 : TestBase | ||
{ | ||
public Issue2176(ITestOutputHelper output) : base(output) { } | ||
|
||
[Fact] | ||
public void Execute_Batch() | ||
{ | ||
using var conn = Create(); | ||
var db = conn.GetDatabase(); | ||
|
||
var me = Me(); | ||
var key = me + ":1"; | ||
var key2 = me + ":2"; | ||
var keyIntersect = me + ":result"; | ||
|
||
db.KeyDelete(key); | ||
db.KeyDelete(key2); | ||
db.KeyDelete(keyIntersect); | ||
db.SortedSetAdd(key, "a", 1345); | ||
|
||
var tasks = new List<Task>(); | ||
var batch = db.CreateBatch(); | ||
tasks.Add(batch.SortedSetAddAsync(key2, "a", 4567)); | ||
tasks.Add(batch.SortedSetCombineAndStoreAsync(SetOperation.Intersect, | ||
keyIntersect, new RedisKey[] { key, key2 })); | ||
var rangeByRankTask = batch.SortedSetRangeByRankAsync(keyIntersect); | ||
tasks.Add(rangeByRankTask); | ||
batch.Execute(); | ||
|
||
Task.WhenAll(tasks.ToArray()); | ||
|
||
var rangeByRankSortedSetValues = rangeByRankTask.Result; | ||
|
||
int size = rangeByRankSortedSetValues.Length; | ||
Assert.Equal(1, size); | ||
string firstRedisValue = rangeByRankSortedSetValues.FirstOrDefault().ToString(); | ||
Assert.Equal("a", firstRedisValue); | ||
} | ||
|
||
[Fact] | ||
public void Execute_Transaction() | ||
{ | ||
using var conn = Create(); | ||
var db = conn.GetDatabase(); | ||
|
||
var me = Me(); | ||
var key = me + ":1"; | ||
var key2 = me + ":2"; | ||
var keyIntersect = me + ":result"; | ||
|
||
db.KeyDelete(key); | ||
db.KeyDelete(key2); | ||
db.KeyDelete(keyIntersect); | ||
db.SortedSetAdd(key, "a", 1345); | ||
|
||
var tasks = new List<Task>(); | ||
var batch = db.CreateTransaction(); | ||
tasks.Add(batch.SortedSetAddAsync(key2, "a", 4567)); | ||
tasks.Add(batch.SortedSetCombineAndStoreAsync(SetOperation.Intersect, | ||
keyIntersect, new RedisKey[] { key, key2 })); | ||
var rangeByRankTask = batch.SortedSetRangeByRankAsync(keyIntersect); | ||
tasks.Add(rangeByRankTask); | ||
batch.Execute(); | ||
|
||
Task.WhenAll(tasks.ToArray()); | ||
|
||
var rangeByRankSortedSetValues = rangeByRankTask.Result; | ||
|
||
int size = rangeByRankSortedSetValues.Length; | ||
Assert.Equal(1, size); | ||
string firstRedisValue = rangeByRankSortedSetValues.FirstOrDefault().ToString(); | ||
Assert.Equal("a", firstRedisValue); | ||
} | ||
} | ||
} |