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
298 stars 48 forks source link

Data persistence for sync and async clients is surprisingly different #297

Closed steve-mavens closed 8 months ago

steve-mavens commented 8 months ago

Describe the bug

The response to https://github.com/cunla/fakeredis-py/issues/293 states that separate fakeredis clients intentionally share state when the same connection parameters are used. However this is not consistent between sync and async clients.

To Reproduce

import asyncio

import fakeredis

async def amain():
    client_1 = fakeredis.FakeAsyncRedis()
    await client_1.set("async_key", "async_value")

    client_2 = fakeredis.FakeAsyncRedis()
    print(f"async_client/async_key {await client_2.get('async_key')}")

def main():
    client_1 = fakeredis.FakeRedis()
    client_1.set("sync_key", "sync_value")
    print(f"original client/sync_key {client_1.get('sync_key')}")

    client_2 = fakeredis.FakeRedis()
    print(f"sync client/async_key {client_2.get('async_key')}")
    print(f"sync client/sync_key {client_2.get('sync_key')}")

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(amain())
    main()

Results:

async_client/async_key b'async_value'
original client/sync_key b'sync_value'
sync client/async_key None
sync client/sync_key None

Expected behavior "sync client/sync_key" expected to be sync_value to match async behaviour. Also I expected the sync and async clients to be drawing from the same shared state as each other, so I expected "sync client/async key" to be async_value.

Desktop (please complete the following information):

Upvote & Fund

Fund with Polar