Carmine appender hk: `conn`->`conn-opts` for consistency wih Carmine v3

This commit is contained in:
Peter Taoussanis 2014-02-20 16:24:45 +07:00
parent 581ab21687
commit 859cfde81f
1 changed files with 9 additions and 8 deletions

View File

@ -31,7 +31,7 @@
also offer interesting opportunities here. also offer interesting opportunities here.
See accompanying `query-entries` fn to return deserialized log entries." See accompanying `query-entries` fn to return deserialized log entries."
[& [appender-opts {:keys [conn keyfn args-hash-fn nentries-by-level] [& [appender-opts {:keys [conn-opts keyfn args-hash-fn nentries-by-level]
:or {keyfn default-keyfn :or {keyfn default-keyfn
args-hash-fn timbre/default-args-hash-fn args-hash-fn timbre/default-args-hash-fn
nentries-by-level {:trace 50 nentries-by-level {:trace 50
@ -40,7 +40,8 @@
:warn 100 :warn 100
:error 100 :error 100
:fatal 100 :fatal 100
:report 100}}}]] :report 100}}
:as opts}]]
{:pre [(string? (keyfn "test")) {:pre [(string? (keyfn "test"))
(every? #(contains? nentries-by-level %) timbre/levels-ordered) (every? #(contains? nentries-by-level %) timbre/levels-ordered)
(every? #(and (integer? %) (<= 0 % 100000)) (vals nentries-by-level))]} (every? #(and (integer? %) (<= 0 % 100000)) (vals nentries-by-level))]}
@ -58,7 +59,7 @@
nmax-entries (nentries-by-level level)] nmax-entries (nentries-by-level level)]
(when (> nmax-entries 0) (when (> nmax-entries 0)
(car/wcar conn (car/wcar (or conn-opts (:conn opts)) ; :conn is Deprecated
(binding [nippy/*final-freeze-fallback* nippy/freeze-fallback-as-str] (binding [nippy/*final-freeze-fallback* nippy/freeze-fallback-as-str]
(car/hset k-hash entry-hash entry)) (car/hset k-hash entry-hash entry))
(car/zadd k-zset udt entry-hash) (car/zadd k-zset udt entry-hash)
@ -89,7 +90,7 @@
Returns latest `n` log entries by level as an ordered vector of deserialized Returns latest `n` log entries by level as an ordered vector of deserialized
maps. Normal sequence fns can be used to query/transform entries. Datomic and maps. Normal sequence fns can be used to query/transform entries. Datomic and
core.logic are also useful!" core.logic are also useful!"
[conn level & [n asc? keyfn]] [conn-opts level & [n asc? keyfn]]
{:pre [(or (nil? n) (and (integer? n) (<= 1 n 100000)))]} {:pre [(or (nil? n) (and (integer? n) (<= 1 n 100000)))]}
(let [keyfn (or keyfn default-keyfn) (let [keyfn (or keyfn default-keyfn)
k-zset (keyfn (name level)) k-zset (keyfn (name level))
@ -97,7 +98,7 @@
entries-zset ; [{:hash _ :level _ :instant _} ...] entries-zset ; [{:hash _ :level _ :instant _} ...]
(->> (->>
(car/wcar conn (car/wcar conn-opts
(if asc? (car/zrange k-zset 0 (if n (dec n) -1) :withscores) (if asc? (car/zrange k-zset 0 (if n (dec n) -1) :withscores)
(car/zrevrange k-zset 0 (if n (dec n) -1) :withscores))) (car/zrevrange k-zset 0 (if n (dec n) -1) :withscores)))
(partition 2) ; Reconstitute :level, :instant keys: (partition 2) ; Reconstitute :level, :instant keys:
@ -109,9 +110,9 @@
entries-hash ; [{_}-or-ex {_}-or-ex ...] entries-hash ; [{_}-or-ex {_}-or-ex ...]
(when-let [hashes (seq (mapv :hash entries-zset))] (when-let [hashes (seq (mapv :hash entries-zset))]
(if-not (next hashes) (if-not (next hashes) ; Careful!
(car/wcar conn :as-pipeline (apply car/hget k-hash hashes)) ; Careful! (car/wcar conn-opts :as-pipeline (apply car/hget k-hash hashes))
(car/wcar conn (apply car/hmget k-hash hashes))))] (car/wcar conn-opts (apply car/hmget k-hash hashes))))]
(mapv (fn [m1 m2-or-ex] (mapv (fn [m1 m2-or-ex]
(if (instance? Exception m2-or-ex) (if (instance? Exception m2-or-ex)