Reputation: 13
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?
Upvotes: 1
Views: 2528
Reputation: 49942
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.
Upvotes: 3
Reputation: 775
Redis uses asynchronous replication and it is not possible to ensure the slave actually received a given write. There will always be a window for data loss.
Upvotes: 1