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

Using watch within a pipline will use a different server_key if host/port are not provided

OlegZv opened this issue · comments

commented

Describe the bug
Using pipe.watch(key) within a pipeline with a client that was created without host or port the client inside the pipeline will use a different server. More generally, if Redis is trying to establish another connection (socket) with a server, it will get a connection to a new empty FakeRedis each time.

To Reproduce

from fakeredis import FakeRedis
fr = FakeRedis() 
fr.set("foo", "barr")
fr.set("boo", "bar")
with fr.pipeline() as pipe:
    keys_before_watch = set(fr.keys())
    pipe.watch("foo")
    assert set(fr.keys()) == keys_before_watch # Fails

Expected behavior
I expect FakeRedis to have the same data with and without a pipeline if I'm using the same instance of the FakeRedis.

Desktop (please complete the following information):

  • Ubuntu 22.04.2 LTC
  • python 3.10.12
  • redis-py version redis==4.6.0

Additional context
I wasn't sure if this is a bug really, because this can also be remediated by creating FakeRedis with some random values of host and port. The example above would work if you initialize fr with fr = FakeRedis(host='blah', port=0).
But to me, it seems more like a workaround, so I opened a PR.

commented

This is related to #140 and #142. I believe as of #140 this was still working. After #142 a new connection from the connection pool would be created to a new/fresh FakeServer within the same pipeline.