Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2012 20:11
Show Gist options
  • Save anonymous/4331526 to your computer and use it in GitHub Desktop.
Save anonymous/4331526 to your computer and use it in GitHub Desktop.
The broken bits of clj-riak
(ns clj-riak.client
"Clojure Riak client."
(:refer-clojure :exclude (get))
(:require [clojure.data.json :as json])
(:import (com.basho.riak.pbc RiakClient RiakObject RiakLink
RequestMeta BucketProperties))
(:import (com.basho.riak.pbc.mapreduce MapReduceResponse))
(:import (com.google.protobuf ByteString))
(:import (org.apache.commons.codec.binary Hex)))
(defn unparse-object [#^String bucket #^String key
{:keys [#^"[B" value content-type #^String vclock]}]
(let [ ro (RiakObject. (vclockstr->bytestr vclock)
(ByteString/copyFromUtf8 bucket)
(ByteString/copyFromUtf8 key)
(ByteString/copyFrom value)) ]
(.setContentType ro content-type)))
(defn put
"Store an object in the given bucket at the given key.
Returns nil, a map, or a seq as for get.
Recobnized obj keys: :value, :content-type
Recognized opts: :w, :dw, :return-body."
[#^RiakClient rc #^String bucket #^String key obj & [opts]]
(let [#^RiakObject ro (unparse-object bucket key obj)
#^RequestMeta rm (unparse-meta opts)]
(parse-objects (.store rc ro rm))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment