Skip to content

Instantly share code, notes, and snippets.

@ragnard
Created March 15, 2010 21:56
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 ragnard/333380 to your computer and use it in GitHub Desktop.
Save ragnard/333380 to your computer and use it in GitHub Desktop.
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.
(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