Created
March 15, 2010 21:56
-
-
Save ragnard/333380 to your computer and use it in GitHub Desktop.
This file contains 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
user=> (doc redis/atomically) | |
------------------------- | |
redis/atomically | |
([& body]) | |
Macro | |
Execute all redis commands in body atomically, ie. sandwiched in a | |
MULTI/EXEC statement. If an exception is thrown the EXEC command | |
will be terminated by a DISCARD, no operations will be performed and | |
the exception will be rethrown. | |
This file contains 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
(deftest atomically | |
(redis/set "key" "value") | |
(is (= ["OK" "OK" "blahong"] | |
(redis/atomically | |
(redis/set "key" "blahonga") | |
(redis/set "key2" "blahong") | |
(redis/get "key2")))) | |
(is (= "blahonga" (redis/get "key")))) | |
(deftest atomically-with-exception | |
(redis/set "key" "value") | |
(is (thrown? Exception | |
(redis/atomically | |
(redis/set "key" "blahonga") | |
(throw (Exception. "Fail")) | |
(redis/set "key2" "blahong")))) | |
(is (= "value" (redis/get "key")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment