Currently I am trying to develop an application using Spring Data Redis but I’m looking for a solution to the current race condition I am facing.
The general idea for the application is:
- Retrieve a key from redis where the value is null (redis will be prepopulated with many keys which are null)
- Update the value to something.
However I with multiple nodes of the application running concurrently, I envision that there could be a race condition where 2 nodes both retrieve the same key and both update the value meaning one node will overwrite the value set by the other node. Instead I would like both nodes to retrieve different keys to update.
I was wondering what would be the best way to avoid this race condition on Spring Data Redis.