Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introduce clojurewerkz.welle.kv/fetch-all

  • Loading branch information...
commit c7beeb7040d63eb1938f9de2978adce018d9ee09 1 parent 5aee5c3
@michaelklishin authored
View
14 src/clojure/clojurewerkz/welle/kv.clj
@@ -1,4 +1,5 @@
(ns clojurewerkz.welle.kv
+ (:require [clojurewerkz.welle.mr :as mr])
(:use clojurewerkz.welle.core
clojurewerkz.welle.conversion
[clojure.walk :only [stringify-keys]])
@@ -63,6 +64,19 @@
from-riak-object
deserialize-value)))))
+(defn fetch-all
+ "Fetches multiple objects concurrently. This is a convenience function: it optimistically assumes there will be only one
+ objects for each key and no siblings. In situations when you are not sure about this, use `clojurewerkz.welle.kv/fetch`
+ `clojure.core/pmap` in combination instead.
+
+ This function relies on clojure.core/pmap to fetch multiple keys,
+ so it may be inappropriate for cases where results need to be retrieved pre-ordered. In such cases, use map/reduce queries
+ instead."
+ [^String bucket-name keys]
+ (pmap (fn [^String k]
+ (fetch-one bucket-name k))
+ keys))
+
(defn index-query
"Performs a secondary index (2i) query. Provided value can be either non-collection
View
18 test/clojurewerkz/welle/test/kv_test.clj
@@ -182,6 +182,24 @@
(is-riak-object fetched)
(drain bucket-name)))
+(deftest test-fetching-of-a-group-of-objects
+ (let [bucket-name "clojurewerkz.welle.kv"
+ bucket (wb/update bucket-name)
+ k1 "multifetch-key1"
+ k2 "multifetch-key2"
+ stored1 (kv/store bucket-name k1 "value1")
+ stored2 (kv/store bucket-name k2 "value2")
+ xs (kv/fetch-many bucket-name [k1 k2])
+ ft1 (first xs)
+ ft2 (last xs)]
+ (is (= "value1" (String. ^bytes (:value ft1))))
+ (is (= "value2" (String. ^bytes (:value ft2))))
+ (doseq [o [ft1 ft2]]
+ (is (= Constants/CTYPE_OCTET_STREAM (:content-type o)))
+ (is (= {} (:metadata o)))
+ (is-riak-object o))
+ (drain bucket-name)))
+
;;
;; kv/delete
;;
Please sign in to comment.
Something went wrong with that request. Please try again.