I make a program that can convert numbers to some Serial numbers by some rules and check if Serial numbers is used. And I use redis to do the check work.
First, get num1 in slave. when result is not nil , it means serial number is used , so return 'used'.
Second, if result is nil, set num1 in master and return 'new' (once return , the nums mean 'used')
The problem is that master will crash before it finish the process of sync with slave , so the number maybe not in slave. At this time get num1 in slave , it return 'new',but the num1 is used.
how to ensure data consistency between master and slave in redis?
Read about the WAIT
command - it allows you to specify the number of slaves that were updated with the most recent change before taking further action.