Skip to content

Batch issue with Sorted Sets in version 2.6.45 #2176

Closed

Description

@mikechoinoski

The latest 2.6.45 version seems to have an issue with batches that previous versions did not.

In the test below a sorted set is created. A batch is then created where another sorted set is created, then an intersect is done between the two sorted sets, then the data should be returned in with SortedSetRangeByRankAsync command. In prior versions, this worked well but in this version no data is returned in the SortedSetRangeByRankAsync command.

It does seem like the first two commands are being executed in the correct order as the intersect key does exist after the test below completes with the correct value. I'm wondering if the SortedSetRangeByRankAsync isn't being executed last though.

In the newest version, I also tried the SortedSetCombineAsync instead of the separate intersect and return data commands and it didn't return any data either.

    using var conn = Create();
    var db = conn.GetDatabase();

    var key = "TestKeyForRedis1";
    var key2 = "TestKeyForRedis2";
    var keyIntersect = "TestKeyForRedisIntersect";

    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);

Activity

  1. mgravell commented on Jun 26, 2022

    @mgravell
    Member

    Definitely sounds weird. Will look.

  2. mgravell commented on Jun 28, 2022

    @mgravell
    Member

    oof; confirmed - the batch is somehow out of order; I see:

    1656409461.024216 [0 127.0.0.1:53158] "UNLINK" "TestKeyForRedis1"
    1656409461.024681 [0 127.0.0.1:53158] "UNLINK" "TestKeyForRedis2"
    1656409461.024831 [0 127.0.0.1:53158] "UNLINK" "TestKeyForRedisIntersect"
    1656409461.025837 [0 127.0.0.1:53158] "ZADD" "TestKeyForRedis1" "1345" "a"
    1656409461.028604 [0 127.0.0.1:53158] "ZRANGE" "TestKeyForRedisIntersect" "0" "-1"
    1656409461.030139 [0 127.0.0.1:53158] "ZADD" "TestKeyForRedis2" "4567" "a"
    1656409461.030470 [0 127.0.0.1:53158] "ZINTERSTORE" "TestKeyForRedisIntersect" "2" "TestKeyForRedis1" "TestKeyForRedis2"

    The last three should be ZADD, ZINTERSTORE, ZRANGE - not ZRANGE, ZADD, ZINTERSTORE

    Marking nuget package as hidden while I investigate this.

  3. mgravell commented on Jun 28, 2022

    @mgravell
    Member

    Right; the issue seems to be a missing override in RedisBatch.cs; I distinctly recall seeing something about this in the last few days, but I can't find it now! If I can't find it to give credit, I'll tweak it myself. Specifically, we need:

    internal override Task<T> ExecuteAsync<T>(Message? message, ResultProcessor<T>? processor, T defaultValue, ServerEndPoint? server = null)
  4. mgravell commented on Jun 28, 2022

    @mgravell
    Member

    crossref #2167 - same problem and solution

  5. added a commit that references this issue on Jun 28, 2022
    b585710
  6. mikechoinoski commented on Jun 28, 2022

    @mikechoinoski
    Author

    Thanks for getting this fixed so quickly!

  7. added a commit that references this issue on Jan 27, 2024
    0ebe530
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions