Use Redis as a way to update a model along a process
Hi all!
I'm currently working on a purchase order process that has several steps before the final checkout, pretty standard, adding products in the basket their quantity and finally asking for the payment method and delivery address.
Currently this process it's been done updating the order at every step in the database, but taking into account that I'm already using Redis to cache the json responses, I was wondering if there is a way to store in Redis all this steps and just at the end, persist the order in the database.
I've seen some examples with to update counter values but nothing that can update an structure already stored in Redis and just update or merge it with new data.
Any advice on this would be appreciated.
Thanks!
If it's just something simple like product IDs, you could use redis. Rails now has kredis which you can use for that: https://github.com/rails/kredis I've been meaning to do a screencast on it.
If it's more complicated, you probably want to store in your database. Redis is just for simple key / value storage so you can't store anything too complex in there. You can sort of cheat and save a json object as the value, but then you have to de/serialize that every time you access it.
Guess it kind of depends on what you're doing as to what would work best.
Thanks Chris!
Your comment just confirmed my thoughts :-) yes was rather complex to deal with the serialized params stored in Redis. I could though do what you said of just storing just product id and quantity and eventually create the order in the database, that may work.
I guess that the next big step would be using Kafka topics for this kind of actions, but not much of these right now to think on implementing that.
Anyway a video using Kafka would be great :-D
Thanks again! good stuff!