Skip to content

Instantly share code, notes, and snippets.

@hboon
Created April 5, 2011 03:08
Show Gist options
  • Save hboon/902956 to your computer and use it in GitHub Desktop.
Save hboon/902956 to your computer and use it in GitHub Desktop.
; a macro in redis-clojure.
(defmacro with-connection [name pool server-spec & body]
`(let [~name (get-connection ~pool ~server-spec)]
(try
~@body
(catch Exception e#
; if we reach here, i.e. an exception, we don't want to run (release-connection) in finally
(release-connection ~pool ~name e#)
(throw e#))
(finally
; don't execute the following if there is any exception above
(release-connection ~pool ~name)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment