Skip to content

Instantly share code, notes, and snippets.

@antirez
Created March 24, 2010 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antirez/342183 to your computer and use it in GitHub Desktop.
Save antirez/342183 to your computer and use it in GitHub Desktop.
# 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