Skip to content

Instantly share code, notes, and snippets.

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 jhalterman/913a96fa130f313a12d8 to your computer and use it in GitHub Desktop.
Save jhalterman/913a96fa130f313a12d8 to your computer and use it in GitHub Desktop.
:cas (timeout 5000 (assoc op :type :info :value :timed-out)
(let [cas (reify Function
(apply [this, tr]
(let [
[value value'] (:value op)
key_var (byte-array (map byte key))
old_value (.getLong (Tuple/fromBytes (.get (.get tr (byte-array (map byte key))))) 0)
new_value (.pack (Tuple/from (into-array [value'])))]
(if (= old_value value)
(do
(.set tr key_var new_value)
(assoc op :type :ok))
(assoc op :type :fail))
)))]
(try
(.run client cas)
(catch RuntimeException e
(assoc op :type :fail :value (.getMessage e))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment