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

FakeAsyncRedis stores state when clear instance expected. #293

Closed
irusland opened this issue Mar 1, 2024 · 4 comments
Closed

FakeAsyncRedis stores state when clear instance expected. #293

irusland opened this issue Mar 1, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@irusland
Copy link

irusland commented Mar 1, 2024

Describe the bug
When creating FakeAsyncRedis each time we get same instance of redis.

To Reproduce

import asyncio

import fakeredis


async def main():
    redis_client_1 = fakeredis.FakeAsyncRedis()
    await redis_client_1.set('k', 'v')

    redis_client_2 = fakeredis.FakeAsyncRedis()
    v2 = await redis_client_2.get('k')

    assert v2 is None, f'Value of new redis is {v2}'


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

produces
AssertionError: Value of new redis is b'v'

Expected behavior
Code runs successfully same as

import fakeredis


def main():
    redis_client_1 = fakeredis.FakeRedis()
    redis_client_1.set('k', 'v')

    redis_client_2 = fakeredis.FakeRedis()
    v2 = redis_client_2.get('k')

    assert v2 is None, f'Value of new redis is {v2}'


if __name__ == '__main__':
    main()

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS Ventura 13.4.1
  • python version: 3.10.12
  • redis-py version: aioredis==2.0.1, redis==5.0.1
  • full requirements.txt: aioredis==2.0.1, fakeredis==2.21.0, redis==5.0.1

Additional context
Not sure if it's an intended behaviour. But anyways I expect same behaviour as FakeRedis

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
@irusland irusland added the bug Something isn't working label Mar 1, 2024
@cunla
Copy link
Owner

cunla commented Mar 1, 2024

It is the intended behavior.

You can supply different connection parameters to get different fake servers.

@irusland
Copy link
Author

irusland commented Mar 1, 2024

Thanks for quick response!

Could you please provide me an example? Or point out the necessary code in documentation?

@irusland
Copy link
Author

irusland commented Mar 1, 2024

Solved it with using different each time port=...

import asyncio

import fakeredis


async def main():
    redis_client_1 = fakeredis.FakeAsyncRedis(port=1)
    await redis_client_1.set('k', 'v')

    redis_client_2 = fakeredis.FakeAsyncRedis(port=2)
    v2 = await redis_client_2.get('k')

    assert v2 is None, f'Value of new redis is {v2}'


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

@irusland irusland closed this as not planned Won't fix, can't repro, duplicate, stale Mar 1, 2024
@cunla
Copy link
Owner

cunla commented Mar 1, 2024

Yeah, that works.
It behaves the same as redis.Redis - by default the connection parameters are localhost:6389.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants