-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
All aio.FakeRedis instances share the same server #218
Comments
We're having the same problem - bug was introduced in 2.17.0 - in previous version it works fine on our end. |
I am afraid that this issue hasn't been fixed by above commit. The change in the place pointed by #218 (comment) wasn't reversed. The problem still occurs in the newest version. Is this change of behavior done on purpose ? |
This issue might relate to changes in d227138 Just to provide possible solution. I think that the default host value in For those facing the issue and need solution immediately, may override the class CustomFakeStrictRedis(fakeredis.FakeStrictRedis):
def __init__(self, *args, server=None, version=(7,), **kwargs):
# To ensure the FakeStrictRedis not gonna sharing the same server
if not server:
server = fakeredis.FakeServer()
super().__init__(*args, server=server, **kwargs) Example case: class xxxxxTestCase(GraphQLTestCase):
def setUp(self):
super().setUp()
self.loaders_get_redis_connection_patcher = patch(
"xxx.loaders.get_redis_connection", CustomFakeStrictRedis
)
self.utils_get_redis_connection_patcher = patch(
"xxxx.utils.get_redis_connection", CustomFakeStrictRedis
)
self.loaders_get_redis_connection_patcher.start()
self.utils_get_redis_connection_patcher.start()
def tearDown(self):
super().tearDown()
self.loaders_get_redis_connection_patcher.stop()
self.utils_get_redis_connection_patcher.stop() |
If you create two redis connections without supplying any connection parameters (host/port/...) it will use the defaults and therefore will use the same server. FakeRedis mimiks this behavior, I am not sure I understand the issue... Please provide a test where you provide different connection parameteers and the result is two connection sharing the server instance. |
You are right. But for some cases we may not provide any connection parameters just like the example I provided. We might do self.loaders_get_redis_connection_patcher = patch(
"xxx.loaders.get_redis_connection", CustomFakeStrictRedis
)
# In patch we cannot pass initiated object (Probably this is a rare case) At
But in
I suspect the reason is because the default value set in Probably this not an issue anymore, if current version of Which mean whenever unique redis connection is needed We need to do this from fakeredis.aioredis import FakeRedis as FakeAsyncRedis
x = FakeAsyncRedis(host="host_one", port=1000)
y = FakeAsyncRedis(host="host_two", port=2000) instead of from fakeredis.aioredis import FakeRedis as FakeAsyncRedis
x = FakeAsyncRedis()
y = FakeAsyncRedis() Then for case not going initialize the fake redis connection, will need to override the
|
Describe the bug
If I create two clients with
fakeredis.aioredis.FakeRedis()
(even with different hosts/ports) they share the same backend.To Reproduce
Raises an AssertionError
Expected behavior
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: