-
Notifications
You must be signed in to change notification settings - Fork 90
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
RedisStorage seems to be broken #155
Comments
Maybe @erfantarighi can look at this. |
@erfantarighi Can you have a look? I currently have storage disabled because of the issue, but in the project I am developing it would probably be good to have storage sooner or later and as I am already using Redis I think RedisStorage would be the best choice. |
@allo- I solved this by subclassing import json
from django_eventstream.event import Event
from django_eventstream.storage import EVENT_TIMEOUT
from django_eventstream.storage import RedisStorage as BaseRedisStorage
class RedisStorage(BaseRedisStorage):
def append_event(self, channel: str, event_type: str, data: dict) -> Event:
"""
Appends a new event to the storage for the specified channel.
Args:
channel (str): The name of the channel to append the event to.
event_type (str): The type of the event.
data (dict): The data associated with the event.
Returns:
Event: An Event object representing the appended event.
"""
with self.redis.pipeline() as pipe:
try:
_event_id = pipe.incr("event_counter:" + channel)
event_data = json.dumps({"type": event_type, "data": data})
pipe.setex(
"event:" + channel + ":" + str(_event_id),
EVENT_TIMEOUT * 60,
event_data,
)
event_id, _ = pipe.execute()
return Event(channel, event_type, data, id=event_id)
except ConnectionError as e:
raise ConnectionError("Failed to append event to Redis.") from e EVENTSTREAM_STORAGE_CLASS = "myapp.storages.RedisStorage" |
When using RedisStorage, I get the error:
unsupported operand type(s) for -: 'Pipeline' and 'int'
atdjango-eventstream/django_eventstream/eventstream.py
Line 58 in 2b61b29
Testing it a bit, I think this line is wrong:
django-eventstream/django_eventstream/storage.py
Line 121 in 2b61b29
and the results of the pipe are only available after
pipe.execute()
. I wanted to tryevent_id, _ = pipe.execute()
, but the data in thepipe.setex
call already needs theevent_id
.Printing the result of pipe.execute without changing other code gives for example
[2, True]
.The text was updated successfully, but these errors were encountered: