'Is it possible to use Redis Pub/Sub persisting latest message?

Currently, I have a project with public transport vehicles, I have to poll the GTFS-RT standard every x seconds and then I will receive the latest data for all vehicles. So to send this to the frontend I am using Redis Pub/Sub with WebSockets.

Currently, however I just publish all the vehicles to redis regardless of any changes. This causes the frontend to re-render everything => slows down the front-end client. I want to actually only publish whenever changes are made to the vehicles. Doing that however means that new listeners would miss out on vehicles. So I would have to persist the latest data for every vehicle.

My question is - is this achievable by replacing Redis Pub/Sub with Redis Streams and then always deleting the current message if another message appears? If that is possible how would I do that? With Pub/Sub I thought about just making a channel for every vehicle and letting the client listen to all the channels, as can be done with pattern matching, but it wouldn't solve the problem of persistence, so what would be the best approach to tackle this problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source