Beach Cleaning Robot Blog

redis pub/sub with websockets - part I

Date: 2021-02-11
Author: Andrew

Slow progress today. With websockets working the next steps is to set up a redis pub/sub arrangement. This arrangement will mean that when a value, say available ram, is updated in redis it will publish the new value to all listeners that are subscribed to that topic. The topic being the key on the key/value pair. Then the Flask server listens for updates and when received passes them to the UI via websockets.

This means I will need to think a little bit about how I structure the topics and values going forward. For now I'm just trying to get it to work!

Firstly, stripped the code out of the server that updates redis with total/available ram and transferred it to a service that updates redis every five seconds. Got that working and running.

Next is where I hit a wall. Wanted to get the pub/sub arrangement occurring by setting up a script that has a listener and will print the updated values when they are published by redis. Started with some sample code and started hacking it up to get the result I wanted. Could not get it to work... Eventually I ran out of time before I needed to go to work so will postpone till tomorrow.