Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for auth with user and password #257

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/workflows/build.yml

This file was deleted.

3 changes: 2 additions & 1 deletion src/taoensso/carmine/commands.clj
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@

(comment
(count command-spec) ; 197
(get command-spec "HMGET")
(clojure.core/get command-spec "HMGET")
(clojure.core/get command-spec "AUTH")
(macroexpand
'(defcommand "HMGET"
{:fn-name "hmget", :fn-docstring "doc", :fn-params-fixed [key field],
Expand Down
4 changes: 2 additions & 2 deletions src/taoensso/carmine/commands.edn
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"XGROUP" {:fn-name "xgroup", :fn-docstring "Create, destroy, and manage consumer groups..\n\nXGROUP [CREATE key groupname id-or-$] [SETID key groupname id-or-$] [DESTROY key groupname] [DELCONSUMER key groupname consumername]\n\nAvailable since: 5.0.0.\n\nTime complexity: O(1) for all the subcommands, with the exception of the DESTROY subcommand which takes an additional O(M) time in order to delete the M entries inside the consumer group pending entries list (PEL).", :fn-params-fixed [], :fn-params-more [& args], :req-args-fixed ["XGROUP"], :cluster-key-idx 1}
"MEMORY USAGE" {:fn-name "memory-usage", :fn-docstring "Estimate the memory usage of a key.\n\nMEMORY USAGE key [SAMPLES count]\n\nAvailable since: 4.0.0.\n\nTime complexity: O(N) where N is the number of samples.", :fn-params-fixed [key], :fn-params-more [key & args], :req-args-fixed ["MEMORY" "USAGE" key], :cluster-key-idx 2}
"BRPOPLPUSH" {:fn-name "brpoplpush", :fn-docstring "Pop an element from a list, push it to another list and return it; or block until one is available.\n\nBRPOPLPUSH source destination timeout\n\nAvailable since: 2.2.0.\n\nTime complexity: O(1)", :fn-params-fixed [source destination timeout], :fn-params-more nil, :req-args-fixed ["BRPOPLPUSH" source destination timeout], :cluster-key-idx 1}
"AUTH" {:fn-name "auth", :fn-docstring "Authenticate to the server.\n\nAUTH password\n\nAvailable since: 1.0.0.\n\n", :fn-params-fixed [password], :fn-params-more nil, :req-args-fixed ["AUTH" password], :cluster-key-idx 1}
"AUTH" {:fn-name "auth", :fn-docstring "Authenticate to the server.\n\nAUTH [username] password\n\nAvailable since: 1.0.0.\n\n", :fn-params-fixed [], :fn-params-more [& args], :req-args-fixed ["AUTH"], :cluster-key-idx 1}
"EXISTS" {:fn-name "exists", :fn-docstring "Determine if a key exists.\n\nEXISTS key [key ...]\n\nAvailable since: 1.0.0.\n\nTime complexity: O(1)", :fn-params-fixed [key], :fn-params-more [key & args], :req-args-fixed ["EXISTS" key], :cluster-key-idx 1}
"CLUSTER FORGET" {:fn-name "cluster-forget", :fn-docstring "Remove a node from the nodes table.\n\nCLUSTER FORGET node-id\n\nAvailable since: 3.0.0.\n\nTime complexity: O(1)", :fn-params-fixed [node-id], :fn-params-more nil, :req-args-fixed ["CLUSTER" "FORGET" node-id], :cluster-key-idx 2}
"CLUSTER SLOTS" {:fn-name "cluster-slots", :fn-docstring "Get array of Cluster slot to node mappings.\n\nCLUSTER SLOTS \n\nAvailable since: 3.0.0.\n\nTime complexity: O(N) where N is the total number of Cluster nodes", :fn-params-fixed [], :fn-params-more nil, :req-args-fixed ["CLUSTER" "SLOTS"], :cluster-key-idx 2}
Expand Down Expand Up @@ -256,4 +256,4 @@
"REPLICAOF" {:fn-name "replicaof", :fn-docstring "Make the server a replica of another instance, or promote it as master..\n\nREPLICAOF host port\n\nAvailable since: 5.0.0.\n\n", :fn-params-fixed [host port], :fn-params-more nil, :req-args-fixed ["REPLICAOF" host port], :cluster-key-idx 1}
"SUNION" {:fn-name "sunion", :fn-docstring "Add multiple sets.\n\nSUNION key [key ...]\n\nAvailable since: 1.0.0.\n\nTime complexity: O(N) where N is the total number of elements in all given sets.", :fn-params-fixed [key], :fn-params-more [key & args], :req-args-fixed ["SUNION" key], :cluster-key-idx 1}
"INCR" {:fn-name "incr", :fn-docstring "Increment the integer value of a key by one.\n\nINCR key\n\nAvailable since: 1.0.0.\n\nTime complexity: O(1)", :fn-params-fixed [key], :fn-params-more nil, :req-args-fixed ["INCR" key], :cluster-key-idx 1}
"MOVE" {:fn-name "move", :fn-docstring "Move a key to another database.\n\nMOVE key db\n\nAvailable since: 1.0.0.\n\nTime complexity: O(1)", :fn-params-fixed [key db], :fn-params-more nil, :req-args-fixed ["MOVE" key db], :cluster-key-idx 1}}
"MOVE" {:fn-name "move", :fn-docstring "Move a key to another database.\n\nMOVE key db\n\nAvailable since: 1.0.0.\n\nTime complexity: O(1)", :fn-params-fixed [key db], :fn-params-more nil, :req-args-fixed ["MOVE" key db], :cluster-key-idx 1}}
15 changes: 9 additions & 6 deletions src/taoensso/carmine/connections.clj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
^Socket socket ^String host ^Integer port true)))

(defn make-new-connection
[{:keys [host port password db conn-setup-fn
[{:keys [host port user password db conn-setup-fn
conn-timeout-ms read-timeout-ms timeout-ms ssl-fn] :as spec}]
(let [;; :timeout-ms controls both :conn-timeout-ms and :read-timeout-ms
;; unless those are specified individually
Expand Down Expand Up @@ -118,7 +118,9 @@
(when (or password db conn-setup-fn)
(protocol/with-context conn
(protocol/with-replies ; Discard replies
(when password (taoensso.carmine/auth password))
(when password (if user
(taoensso.carmine/auth user password)
(taoensso.carmine/auth password)))
(when db (taoensso.carmine/select (str db)))
(when conn-setup-fn
(conn-setup-fn {:conn conn :spec spec})))))
Expand Down Expand Up @@ -208,10 +210,11 @@
port (.getPort uri)
db (if-let [[_ db-str] (re-matches #"/(\d+)$" (.getPath uri))]
(Integer. ^String db-str))]
(-> {:host (.getHost uri)}
(#(if (pos? port) (assoc % :port port) %))
(#(if (and db (pos? db)) (assoc % :db db) %))
(#(if password (assoc % :password password) %))))))
(cond-> {:host (.getHost uri)}
(pos? port) (assoc :port port)
(and db (pos? db)) (assoc :db db)
password (assoc :password password)
user (assoc :user user)))))

(comment (parse-uri "redis://redistogo:[email protected]:9475/7"))

Expand Down
6 changes: 4 additions & 2 deletions src/taoensso/carmine/message_queue.clj
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@
:success (done status mid backoff-ms)
:retry (done status mid backoff-ms)
:error (error mid poll-reply throwable)
(do (done :success mid) ; For backwards-comp with old API
(timbre/warnf "Invalid handler status: %s" status))))))
(do
(done :success mid) ; For backwards-comp with old API
(timbre/warn "Invalid handler status"
{:qname qname :status status :mid mid}))))))

;;;; Workers

Expand Down