Sunday, November 13, 2011

[Workaround] Riak create object without key

Unfortunately today's java-riak interface does not allow creating objects without specifying a key. This means effectively sending a POST rather than a PUT and not including a key (or setting key=null). For my needs, I was calling the java lib through clojure. My workaround? Pre-manufacture UUIDs:

(defn riak-post [client bucket obj]
  (let [key (uuid/uuid)]
    (client/put client bucket key
                {:value (.getBytes obj)
                 :content-type "text/plain"})
    key))

0 comments: