Created
March 24, 2010 11:09
-
-
Save antirez/342183 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We want to create our new object, and make sure it is in the Set of existing objects. | |
1) INCR object.nextid => 1000 # Get an unique ID for the next object | |
2) SET object:1000 "my object value" # Set the value of the object | |
3) SADD all.my.objects 1000 # Add the ID of the object to the target Set, representing all the objects | |
What happens if the client dies between 2 and 3? We have the object key, but "leaked" it forever as it's no longer in Set of our objects. | |
MULTI/EXEC fix this problem: | |
1) INCR object:nextid => 1000 | |
2) MULTI | |
3) SET object:1000 ... | |
4) SADD all.my.objects 1000 | |
5) EXEC | |
Either both the operations are performed or none, no inconsistent state in our dataset. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment