From 0723f7d588b3da1e7709f7b0443af30bc4b0f5f4 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Sun, 30 Sep 2018 17:35:46 +0200 Subject: [PATCH] [Lua/refactor] Avoid `apply` on lua calls --- src/taoensso/carmine.clj | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/taoensso/carmine.clj b/src/taoensso/carmine.clj index e3db5de6..4d53f090 100644 --- a/src/taoensso/carmine.clj +++ b/src/taoensso/carmine.clj @@ -154,26 +154,32 @@ (def script-hash (memoize (fn [script] (sha1-str script)))) +(defn- -evalsha* [script numkeys args] + (redis-call (into [:evalsha (script-hash script) numkeys] args))) + (defn evalsha* "Like `evalsha` but automatically computes SHA1 hash for script." - [script numkeys & args] (apply evalsha (script-hash script) numkeys args)) + [script numkeys & args] (-evalsha* script numkeys args)) -(defn eval* - "Optimistically tries to send `evalsha` command for given script. In the event - of a \"NOSCRIPT\" reply, reattempts with `eval`. Returns the final command's - reply. Redis Cluster note: keys need to all be on same shard." - [script numkeys & args] +(defn- -eval* [script numkeys args] (let [parser ; Respect :raw-bulk, otherwise ignore parser: (if-not (:raw-bulk? (meta protocol/*parser*)) nil ; As `parse-raw`: (with-meta identity {:raw-bulk? true})) [r & _] ; & _ for :as-pipeline (parse parser (with-replies :as-pipeline - (apply evalsha* script numkeys args)))] + (-evalsha* script numkeys args)))] + (if (= (:prefix (ex-data r)) :noscript) ;;; Now apply context's parser: - (apply eval script numkeys args) + (redis-call (into [:eval script numkeys] args)) (return r)))) +(defn eval* + "Optimistically tries to send `evalsha` command for given script. In the event + of a \"NOSCRIPT\" reply, reattempts with `eval`. Returns the final command's + reply. Redis Cluster note: keys need to all be on same shard." + [script numkeys & args] (-eval* script numkeys args)) + (comment (wcar {} (redis-call ["eval" "return 10;" 0])) (wcar {} (eval "return 10;" 0))