Skip to content

Commit

Permalink
Really atomic get and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
matti committed May 3, 2010
1 parent f4d9a90 commit 6e436af
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions recipes/2_basic_commands/get_and_delete/meta.yml
Expand Up @@ -3,6 +3,7 @@ title: Atomic Get and Delete
credit:
- Gleicon Moraes
- Dov Murik
- Matti Paksula
tags:
- tricks
- atomic
34 changes: 34 additions & 0 deletions recipes/2_basic_commands/get_and_delete/recipe.md
Expand Up @@ -39,5 +39,39 @@ because the key was already renamed. GET and DEL benefit from the RENAME
function in order to keep other clients from reading the object data between
operations.

This is potentially dangerous.

### Problems with the solution proposed above

If the execution is interrupted in line 2 (if success) or 3 (value = GET key:tmp) then that key stays renamed as key:tmp for good in the database.

### Real atomic solution

in pseudocode:

MULTI
value = GET key
DELETE key
EXEC
return value

using `redis-cli`:

redis> SET TOTO 1
OK
redis> GET TOTO
1
redis> MULTI
OK
redis> GET TOTO
QUEUED
redis> DEL TOTO
QUEUED
redis> EXEC
1. 1
2. (integer) 1
redis> GET TOTO
(nil)

### See Also

0 comments on commit 6e436af

Please sign in to comment.