In this episode, we dive into how to fetch the checkbox states from Redis and transform them into a usable format. We start by jumping into the home controller and try dumping out the raw state from Redis, which for now is just a binary string—not super useful by itself.
To make sense of it, we break that state string apart into individual characters and use functions to convert each character into its ordinal value (so we see the decimal representation for the byte), and then further convert those decimals into binary strings. This lets us visualize the on/off (checked/unchecked) status of each checkbox. We also pad each binary value with zeros to ensure they're all full bytes and then concatenate them into one long binary string representing all checkbox states.
Finally, we clean up the code a little, bundle all that state data, and set it up so it can be passed down to our component as initial checkbox states, along with how many boxes there are. We even add a count()
method using Redis's bitcount
command to easily see how many checkboxes have been checked in total!
By the end, you’ll see how data saved as a compact binary blob in Redis can be unpacked into a user-friendly format, ready to power your checkboxes in the UI.