cunla / fakeredis-py

Implementation of Redis in python without having a Redis server running. Fully compatible with using redis-py.
https://fakeredis.moransoftware.ca/
BSD 3-Clause "New" or "Revised" License
281 stars 47 forks source link

Change in redis-py v5.0.8 causes strange behavior in fakeredis-py #316

Closed x0ul closed 1 month ago

x0ul commented 1 month ago

Describe the bug

fakeredis-py returns unexpected values for get that appear to be left over results from the previous command

To Reproduce Steps to reproduce the behavior:

Run the following test case with pytest

    @pytest.mark.asyncio
    async def test_cause_fakeredis_bug():
        redis = fakeredis.FakeAsyncRedis()

        async def worker_task():
            await redis.rpush("list1", "list1_val")
            assert await redis.blpop("list2") == (b"list2", b"list2_val")
            await redis.set("foo", "bar")

        async with asyncio.TaskGroup() as tg:
            tg.create_task(worker_task())
            assert await redis.blpop("list1") == (b"list1", b"list1_val")
            await redis.rpush("list2", "list2_val")

        # await redis.get("foo")  # uncomment to make test pass
>       assert await redis.get("foo") == b"bar"
E       AssertionError: assert b'OK' == b'bar'
E         
E         At index 0 diff: b'O' != b'b'
E         
E         Full diff:
E         - b'bar'
E         + b'OK'

Expected behavior Test passes. This test passes with redis-py v5.0.7.

Screenshots N/A

Desktop (please complete the following information):

Additional context Doing another get (see commented-out line in test case above) seems to re-sync the connection and cause the test to pass.

Upvote & Fund

Fund with Polar

cunla commented 1 month ago

I am surprised this is the first time this was mentioned. Anyway, should be fixed.

x0ul commented 1 month ago

Thanks so much for the quick fix, I seriously appreciate what this library has helped me do. Was removing this call to put_response the main change?

cunla commented 1 month ago

yes, it is writing the response a few lines afterwards in the finally section