-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[new] [#282] Add support for TLS URIs to URI parser
- Loading branch information
1 parent
2e6722b
commit 19d97eb
Showing
2 changed files
with
22 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ | |
`spec` describes the connection details, e.g.: | ||
- {:host \"127.0.0.1\" :port 6379} ; Default | ||
- {:uri \"redis://redistogo:[email protected].com:9475/\"} | ||
- {:uri \"redis://username:[email protected].com:9475/3\" ; /3 for db 3 | ||
- {:host \"127.0.0.1\" | ||
:port 6379 | ||
:ssl-fn :default ; [1] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,15 @@ | |
"Handles socket connection lifecycle. Pool is implemented with Apache Commons | ||
pool. Originally adapted from redis-clojure." | ||
{:author "Peter Taoussanis"} | ||
(:require [taoensso.encore :as enc] | ||
[taoensso.carmine.protocol :as protocol]) | ||
(:import [java.net InetSocketAddress Socket URI] | ||
[org.apache.commons.pool2 KeyedPooledObjectFactory] | ||
[org.apache.commons.pool2.impl GenericKeyedObjectPool DefaultPooledObject])) | ||
(:require | ||
[clojure.string :as str] | ||
[taoensso.encore :as enc] | ||
[taoensso.carmine.protocol :as protocol]) | ||
|
||
(:import | ||
[java.net InetSocketAddress Socket URI] | ||
[org.apache.commons.pool2 KeyedPooledObjectFactory] | ||
[org.apache.commons.pool2.impl GenericKeyedObjectPool DefaultPooledObject])) | ||
|
||
(enc/declare-remote | ||
taoensso.carmine/ping | ||
|
@@ -233,18 +237,25 @@ | |
[username password] (.split (str (.getUserInfo uri)) ":") | ||
port (.getPort uri) | ||
db (when-let [[_ db-str] (re-matches #"/(\d+)$" (.getPath uri))] | ||
(Integer. ^String db-str))] | ||
(Integer. ^String db-str)) | ||
|
||
ssl-fn | ||
(when-let [scheme (.getScheme uri)] | ||
(when (contains? #{"rediss" "https"} (str/lower-case scheme)) | ||
:default))] | ||
|
||
(-> {:host (.getHost uri)} | ||
(#(if (pos? port) (assoc % :port port) %)) | ||
(#(if (and db (pos? (long db))) (assoc % :db db) %)) | ||
(#(if (enc/nempty-str? username) (assoc % :username username) %)) | ||
(#(if (enc/nempty-str? password) (assoc % :password password) %)))))) | ||
(#(if (enc/nempty-str? password) (assoc % :password password) %)) | ||
(#(if ssl-fn (assoc % :ssl-fn ssl-fn) %)))))) | ||
|
||
(comment | ||
[(parse-uri "redis://user:[email protected]:9475/7") | ||
(parse-uri "redis://:[email protected]:9475/7") | ||
(parse-uri "redis://user:@x.y.com:9475/7")]) | ||
[(parse-uri "redis://user:[email protected]:9475/3") | ||
(parse-uri "redis://:[email protected]:9475/3") | ||
(parse-uri "redis://user:@x.y.com:9475/3") | ||
(parse-uri "rediss://user:@x.y.com:9475/3")]) | ||
|
||
(def conn-spec | ||
(enc/memoize | ||
|