I have a nodejs application running (haraka smtp server) with 1 master thread and 7 worker threads . I'm using redis to read some counters and after some operations I'm updating those counters.
I'm facing the issue of race condition where some of the threads are reading the counters before other threads actually updates it, hence there is a mismatch in counters. Ideally it should be like one thread do its read and write operation on that particular key and then others should proceed with there ops.
I have currently a single instance of redis running. Is it a way to avoid this race condition with multiple threads and single redis instance ?
I've read about redlock but redis website says its best to use redlock with atleast 3 redis instances.