Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SET EX NX does not set a string longer than expired #771

Closed
nightroman opened this issue Nov 5, 2024 · 1 comment
Closed

SET EX NX does not set a string longer than expired #771

nightroman opened this issue Nov 5, 2024 · 1 comment

Comments

@nightroman
Copy link
Contributor

nightroman commented Nov 5, 2024

Describe the bug

SET EX NX does not set a string longer than expired, e.g. if the expired
string is "short" (length 5) and the new value is "longer" (length 6) then
the result is true as expected ~ the string is set, but the new string is
not actually stored, the key does not exist.

Steps to reproduce the bug

    [Fact]
    public void ExistingExpired6379()
    {
        var redis = ConnectionMultiplexer.Connect("127.0.0.1:6379,SyncTimeout=999999");
        var db = redis.GetDatabase();

        var key = "test:lock1";
        var value1 = "short";
        var value2 = "longer";
        var ttl1 = TimeSpan.FromMilliseconds(200);
        var ttl2 = TimeSpan.FromMinutes(1);

        // set expiring string "short" and let it expire
        db.StringSet(key, value1, ttl1);
        Thread.Sleep(ttl1 * 2);

        // set expiring string "longer" over expired "short" -> true ~ expected
        bool ok = db.StringSet(key, value2, ttl2, When.NotExists);
        Assert.True(ok);

        // but the expected string does not exist, null is returned, assert fails
        string? str = db.StringGet(key);
        Assert.Equal(value2, str);
    }

Expected behavior

The above xunit test is supposed to pass (new string exists) but it fails (the string does not exist, although the operation returned true).

Note that the test passes is we use a shorter string as value2, e.g. "longe" instead of "longer".

Release version

1.0.35

IDE

Microsoft Visual Studio Community 2022 (64-bit) - 17.11.5

OS version

Windows 11

@Vijay-Nirmal
Copy link
Contributor

Vijay-Nirmal commented Nov 5, 2024

Raised a PR to fix it #772

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants