Skip to content

Commit

Permalink
[v4] Rename rcall -> rcmd, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Sep 19, 2024
1 parent 37ea478 commit f70bfa8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 44 deletions.
14 changes: 7 additions & 7 deletions src/taoensso/carmine_v4.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
write/freeze

;;; RESP3
resp/rcall
resp/rcall*
resp/rcalls
resp/rcalls*
resp/rcmd
resp/rcmd*
resp/rcmds
resp/rcmds*
resp/local-echo
resp/local-echos
resp/local-echos*
Expand Down Expand Up @@ -269,9 +269,9 @@
(doseq [mgr [mgr1 mgr2 mgr3]]
(conns/mgr-close! mgr 5000 nil)))))

[(wcar nil (resp/rcall "PING"))
(wcar nil (resp/rcall "set" "k1" 3))
(wcar nil (resp/rcall "get" "k1"))
[(wcar nil (resp/rcmd :PING))
(wcar nil (resp/rcmd :SET "k1" 3))
(wcar nil (resp/rcmd :GET "k1"))

(wcar nil (resp/ping))
(wcar nil {:as-vec? true} (resp/ping))
Expand Down
2 changes: 1 addition & 1 deletion src/taoensso/carmine_v4/cluster.clj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
;; - Slots can be determined automatically for auto-generated commands:
;; - First arg after command name seems to usu. indicate "key".
;; - If there's any additional keys, their slots would anyway need to agree
;; - `rcall` and co. expect `cluster-key` to be called manually on the appropriate arg
;; - `rcmd` and co. expect `cluster-key` to be called manually on the appropriate arg

;; [ ]
;; Stateful ClusterSpec:
Expand Down
2 changes: 1 addition & 1 deletion src/taoensso/carmine_v4/conns.clj
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
replies
(try
(resp/with-replies in out :natural-replies :as-vec
(fn [] (run! resp/rcall* reqs)))
(fn [] (run! resp/rcmd* reqs)))

(catch Throwable t (vreset! conn-error_ t) nil))

Expand Down
36 changes: 18 additions & 18 deletions src/taoensso/carmine_v4/resp.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
(let [get-read-opts get-read-opts
cluster-slot cluster/cluster-slot]

(defn ^:public rcall*
(defn ^:public rcmd*
"Sends 1 arbitrary command to Redis server.
Takes a vector of args for the command call:
(wcar {} (rcall* [\"set\" \"my-key\" \"my-val\"])) => \"OK\"
(wcar {} (rcmd* [:SET \"my-key\" \"my-val\"])) => \"OK\"
Useful for DSLs, and to call commands (including Redis module commands)
that might not yet have a native Clojure fn provided by Carmine."
Expand All @@ -87,12 +87,12 @@
nil)
(throw-no-ctx! cmd-args)))

(defn ^:public rcalls*
(defn ^:public rcmds*
"Send >=0 arbitrary commands to Redis server.
Takes a vector of calls, with each call a vector of args:
(wcar {}
(rcalls* [[\"set\" \"my-key\" \"my-val\"]
[\"get\" \"my-key\"]])) => [\"OK\" \"my-val\"]
(rcmds* [[:SET \"my-key\" \"my-val\"]
[:GET \"my-key\"]])) => [\"OK\" \"my-val\"]
Useful for DSLs, and to call commands (including Redis module commands)
that might not yet have a native Clojure fn provided by Carmine."
Expand All @@ -109,27 +109,27 @@
nil)
(throw-no-ctx! cmds))))

(let [rcall* rcall*]
(defn ^:public rcall
(let [rcmd* rcmd*]
(defn ^:public rcmd
"Sends 1 arbitrary command to Redis server.
Takes varargs for the command call:
(wcar {} (rcall \"set\" \"my-key\" \"my-val\")) => \"OK\"
(wcar {} (rcmd :SET \"my-key\" \"my-val\")) => \"OK\"
Useful for DSLs, and to call commands (including Redis module commands)
that might not yet have a native Clojure fn provided by Carmine."
[& cmd-args] (rcall* cmd-args)))
[& cmd-args] (rcmd* cmd-args)))

(let [rcalls* rcalls*]
(defn ^:public rcalls
(let [rcmds* rcmds*]
(defn ^:public rcmds
"Send >=0 arbitrary commands to Redis server.
Takes vararg calls, with each call a vector of args:
(wcar {}
(rcalls [\"set\" \"my-key\" \"my-val\"]
[\"get\" \"my-key\"])) => [\"OK\" \"my-val\"]
(rcmds [:SET \"my-key\" \"my-val\"]
[:GET \"my-key\"])) => [\"OK\" \"my-val\"]
Useful for DSLs, and to call commands (including Redis module commands)
that might not yet have a native Clojure fn provided by Carmine."
[& cmds] (rcalls* cmds)))
[& cmds] (rcmds* cmds)))

(let [get-read-opts get-read-opts]
(defn ^:public local-echo
Expand Down Expand Up @@ -163,10 +163,10 @@
[& xs] (local-echos* xs)))

(do ; Basic commands for tests
(defn ping [] (rcall "PING"))
(defn echo [x] (rcall "ECHO" x))
(defn rset [k v] (rcall "SET" k v))
(defn rget [k] (rcall "GET" k)))
(defn ping [] (rcmd "PING"))
(defn echo [x] (rcmd "ECHO" x))
(defn rset [k v] (rcmd "SET" k v))
(defn rget [k] (rcmd "GET" k)))

;;;; Non-cluster API

Expand Down
16 changes: 8 additions & 8 deletions src/taoensso/carmine_v4/sentinel.clj
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,16 @@ sentinel down-after-milliseconds %3$s 60000"
(resp/with-replies in out :natural-replies :as-vec
(fn []
;; Always ask about master (may be used as fallback when no replicas)
(resp/rcall "SENTINEL" "get-master-addr-by-name" master-name)
(resp/rcmd "SENTINEL" "get-master-addr-by-name" master-name)

(if (or prefer-read-replica? update-replicas?)
;; Ask about replica nodes
(resp/rcall "SENTINEL" "replicas" master-name)
(resp/rcmd "SENTINEL" "replicas" master-name)
(resp/local-echo nil))

(when update-sentinels?
;; Ask about sentinel nodes
(resp/rcall "SENTINEL" "sentinels" master-name))))))
(resp/rcmd "SENTINEL" "sentinels" master-name))))))

(catch Throwable _
[::unreachable nil nil])))]
Expand Down Expand Up @@ -386,7 +386,7 @@ sentinel down-after-milliseconds %3$s 60000"
(conns/with-new-conn conn-opts host port master-name
(fn [_ in out]
(resp/with-replies in out :natural-replies false
(fn [] (resp/rcall "ROLE")))))
(fn [] (resp/rcmd "ROLE")))))
(catch Throwable _ nil))]

(when (vector? reply) (get reply 0)))]
Expand Down Expand Up @@ -492,7 +492,7 @@ sentinel down-after-milliseconds %3$s 60000"
(fn [_ in out]
(resp/with-replies in out false false
(fn []
(resp/rcall "ROLE")
#_(resp/rcall "SENTINEL" "get-master-addr-by-name" "my-master")
#_(resp/rcall "SENTINEL" "replicas" "my-master")
#_(core/rcall "SENTINEL" "sentinels" "my-master"))))))
(resp/rcmd "ROLE")
#_(resp/rcmd "SENTINEL\" \"get-master-addr-by-name\" \"my-master\"")
#_(resp/rcmd "SENTINEL\" \"replicas\" \"my-master\"")
#_(core/rcmd "SENTINEL\" \"sentinels\" \"my-master\""))))))
18 changes: 9 additions & 9 deletions test/taoensso/carmine_v4/tests/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

(let [delete-test-keys
(fn []
(when-let [ks (seq (wcar mgr_ (resp/rcall "keys" (tk "*"))))]
(wcar mgr_ (doseq [k ks] (resp/rcall "del" k)))))]
(when-let [ks (seq (wcar mgr_ (resp/rcmd "KEYS" (tk "*"))))]
(wcar mgr_ (doseq [k ks] (resp/rcmd "DEL" k)))))]

(test/use-fixtures :once
(enc/test-fixtures
Expand Down Expand Up @@ -153,7 +153,7 @@
[(v+ (#'conns/conn? conn))
(v+ (#'conns/conn-ready? conn))
(v+ (resp/ping))
(v+ (car/with-replies (resp/rcall "echo" "x")))])))
(v+ (car/with-replies (resp/rcmd "ECHO" "x")))])))

[@v mgr])))

Expand All @@ -164,7 +164,7 @@
(#'conns/conn-ready? conn)
(resp/basic-ping! in out)
(resp/with-replies in out false false
(fn [] (resp/rcall "echo" "x")))]))
(fn [] (resp/rcmd "ECHO" "x")))]))
[true true "PONG" "x"])
"Unmanaged conn")

Expand All @@ -185,11 +185,11 @@
f
(future
(wcar mgr
(resp/rcalls
["del" k1]
["lpush" k1 "x"]
["lpop" k1]
["blpop" k1 5] ; Block for 5 secs
(resp/rcmds
["DEL" k1]
["LPUSH" k1 "x"]
["LPOP" k1]
["BLPOP" k1 5] ; Block for 5 secs
)))]

(Thread/sleep 1000) ; Wait for wcar to start but not complete
Expand Down

0 comments on commit f70bfa8

Please sign in to comment.