I’ve been using josiahcarlson’s Redis Object Mapper (ROM) to work with my data in Redis. I need certain operations to be done as transactions, i.e. either all writes are done or none are done (auto rollback in case of any error or shutdown).
From what I could find online, Josiah had a conversation with the maintainer of Redis, who didn’t agree to accept the PR for transactions back in 2015. What is the situation now? I couldn’t find anything about this in the docs nor in Google.
How do I implement atomicity for my operations with ROM? Is there a way?
2
Answers
There are multiple functions in ROM which uses atomicity. Here is a link with the documentation of all the functions in ROM:
https://readthedocs.org/projects/redis-py/downloads/pdf/latest/
As seen, functions such as:
All allow you to implement atomicity in the Redits Object Mapper.
Hope this helps!
It was not previously built into rom (the earlier version). If you want to go fast and loose, we’ll keep a temp transaction id in a common place (which you can verify afterwards, if you need to). If you want to go official, you will want a transaction history / ledger, which will take a little more work (you can use the ledger model for storing value, then mark it as done as part of the transaction).
If you want to use built-in functionality plus your own model data to transfer, you can use something like we have in the tests: https://github.com/josiahcarlson/rom/blob/1.0.0/test/test_rom.py#L1759
The function below will transfer a value, and refresh your local models. Returns
(successful_transfer, optional_message)
.