cunla / fakeredis-py

Implementation of Redis in python without having a Redis server running. Fully compatible with using redis-py.

Home Page:https://fakeredis.moransoftware.ca/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Data persistence for sync and async clients is surprisingly different

steve-mavens opened this issue · comments

Describe the bug

The response to #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):

  • OS: [e.g. iOS] Windows 10
  • python version 3.8.16
  • redis-py version 5.0.2
  • full requirements.txt? fakeredis 2.21.1

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar