diff --git a/Cargo.lock b/Cargo.lock index 10789a60..896a1560 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,107 +138,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" -[[package]] -name = "async-channel" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59740d83946db6a5af71ae25ddf9562c2b176b2ca42cf99a455f09f4a220d6b9" -dependencies = [ - "concurrent-queue", - "event-listener", - "futures-core", -] - -[[package]] -name = "async-executor" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146" -dependencies = [ - "async-task", - "concurrent-queue", - "fastrand", - "futures-lite", - "once_cell", - "vec-arena", -] - -[[package]] -name = "async-global-executor" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73079b49cd26b8fd5a15f68fc7707fc78698dc2a3d61430f2a7a9430230dfa04" -dependencies = [ - "async-executor", - "async-io", - "futures-lite", - "num_cpus", - "once_cell", -] - -[[package]] -name = "async-io" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9315f8f07556761c3e48fec2e6b276004acf426e6dc068b2c2251854d65ee0fd" -dependencies = [ - "concurrent-queue", - "fastrand", - "futures-lite", - "libc", - "log 0.4.11", - "nb-connect", - "once_cell", - "parking", - "polling", - "vec-arena", - "waker-fn", - "winapi 0.3.9", -] - -[[package]] -name = "async-mutex" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-std" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f9f84f1280a2b436a2c77c2582602732b6c2f4321d5494d6e799e6c367859a8" -dependencies = [ - "async-channel", - "async-global-executor", - "async-io", - "async-mutex", - "blocking", - "crossbeam-utils 0.8.1", - "futures-channel", - "futures-core", - "futures-io", - "futures-lite", - "gloo-timers", - "kv-log-macro", - "log 0.4.11", - "memchr", - "num_cpus", - "once_cell", - "pin-project-lite 0.2.1", - "pin-utils", - "slab", - "wasm-bindgen-futures", -] - -[[package]] -name = "async-task" -version = "4.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" - [[package]] name = "async-trait" version = "0.1.42" @@ -250,12 +149,6 @@ dependencies = [ "syn", ] -[[package]] -name = "atomic-waker" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" - [[package]] name = "atty" version = "0.2.14" @@ -391,20 +284,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" -[[package]] -name = "blocking" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" -dependencies = [ - "async-channel", - "async-task", - "atomic-waker", - "fastrand", - "futures-lite", - "once_cell", -] - [[package]] name = "boxfnonce" version = "0.1.1" @@ -462,12 +341,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad1f8e949d755f9d79112b5bb46938e0ef9d3804a0b16dfab13aafcaa5f0fa72" -[[package]] -name = "cache-padded" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" - [[package]] name = "cachepot" version = "0.1.0" @@ -633,15 +506,6 @@ dependencies = [ "tokio 0.2.24", ] -[[package]] -name = "concurrent-queue" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" -dependencies = [ - "cache-padded", -] - [[package]] name = "conhash" version = "0.4.0" @@ -913,12 +777,6 @@ dependencies = [ "version_check 0.9.2", ] -[[package]] -name = "event-listener" -version = "2.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" - [[package]] name = "failure" version = "0.1.8" @@ -941,15 +799,6 @@ dependencies = [ "synstructure", ] -[[package]] -name = "fastrand" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca5faf057445ce5c9d4329e382b2ce7ca38550ef3b73a5348362d5f24e0c7fe3" -dependencies = [ - "instant", -] - [[package]] name = "filetime" version = "0.2.13" @@ -1106,21 +955,6 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e37c1a51b037b80922864b8eed90692c5cd8abd4c71ce49b77146caa47f3253b" -[[package]] -name = "futures-lite" -version = "1.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb" -dependencies = [ - "fastrand", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite 0.2.1", - "waker-fn", -] - [[package]] name = "futures-locks" version = "0.6.0" @@ -1241,19 +1075,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -[[package]] -name = "gloo-timers" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "h2" version = "0.1.26" @@ -1605,15 +1426,6 @@ dependencies = [ "winapi-build", ] -[[package]] -name = "kv-log-macro" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" -dependencies = [ - "log 0.4.11", -] - [[package]] name = "language-tags" version = "0.2.2" @@ -1911,16 +1723,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "nb-connect" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8123a81538e457d44b933a02faf885d3fe8408806b23fa700e8f01c6c3a98998" -dependencies = [ - "libc", - "winapi 0.3.9", -] - [[package]] name = "net2" version = "0.2.37" @@ -2151,12 +1953,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "parking" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" - [[package]] name = "parking_lot" version = "0.9.0" @@ -2395,19 +2191,6 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" -[[package]] -name = "polling" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "log 0.4.11", - "wepoll-sys", - "winapi 0.3.9", -] - [[package]] name = "polyval" version = "0.4.5" @@ -2740,17 +2523,17 @@ version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95357caf2640abc54651b93c98a8df4fe1ccbf44b8e601ccdf43d5c1451f29ac" dependencies = [ - "async-std", "async-trait", "bytes 0.5.6", "combine", "dtoa", "futures-util", "itoa", + "native-tls", "percent-encoding 2.1.0", "pin-project-lite 0.1.11", - "sha1", "tokio 0.2.24", + "tokio-tls", "tokio-util", "url 2.2.0", ] @@ -4056,12 +3839,6 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" -[[package]] -name = "vec-arena" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" - [[package]] name = "vec_map" version = "0.8.2" @@ -4110,12 +3887,6 @@ dependencies = [ "libc", ] -[[package]] -name = "waker-fn" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" - [[package]] name = "walkdir" version = "2.3.1" @@ -4238,15 +4009,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "wepoll-sys" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" -dependencies = [ - "cc", -] - [[package]] name = "which" version = "4.0.2" diff --git a/Cargo.toml b/Cargo.toml index 55d230dc..158e0303 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,7 @@ num_cpus = "1.0" number_prefix = "0.4" percent-encoding = { version = "2", optional = true } rand = "0.8" -redis = { version = "0.17", optional = true } +redis = { version = "0.17", optional = true, default-features = false, features = ["aio", "tls", "tokio-comp", "tokio-tls-comp"] } regex = "1" reqwest = { version = "0.10", features = ["json", "blocking"], optional = true } retry = "1" diff --git a/README.md b/README.md index 68f9a9ea..75ca1acd 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,8 @@ You can also define a prefix that will be prepended to the keys of all cache obj ### Redis Set `CACHEPOT_REDIS` to a [Redis](https://redis.io/) url in format `redis://[:@][:port][/]` to store the cache in a Redis instance. Redis can be configured as a LRU (least recently used) cache with a fixed maximum cache size. Set `maxmemory` and `maxmemory-policy` according to the [Redis documentation](https://redis.io/topics/lru-cache). The `allkeys-lru` policy which discards the *least recently accessed or modified* key fits well for the cachepot use case. +Redis over TLS is supported. Use the [`rediss://`](https://www.iana.org/assignments/uri-schemes/prov/rediss) url scheme (note `rediss` vs `redis`). Append `#insecure` the the url to disable hostname verification and accept self-signed certificates (dangerous!). Note that this also disables [SNI](https://en.wikipedia.org/wiki/Server_Name_Indication). + ### Memcached Set `CACHEPOT_MEMCACHED` to a [Memcached](https://memcached.org/) url in format `tcp://: ...` to store the cache in a Memcached instance. diff --git a/src/cache/redis.rs b/src/cache/redis.rs index d657bb5e..0f8aa6e5 100644 --- a/src/cache/redis.rs +++ b/src/cache/redis.rs @@ -20,19 +20,25 @@ use redis::{cmd, Client, InfoDict}; use std::collections::HashMap; use std::io::Cursor; use std::time::{Duration, Instant}; +use url::Url; /// A cache that stores entries in a Redis. #[derive(Clone)] pub struct RedisCache { - url: String, + display_url: String, // for display only: password (if any) will be masked client: Client, } impl RedisCache { /// Create a new `RedisCache`. pub fn new(url: &str) -> Result { + let mut parsed = Url::parse(url)?; + // If the URL has a password set, mask it when displaying. + if parsed.password().is_some() { + let _ = parsed.set_password(Some("*****")); + } Ok(RedisCache { - url: url.to_owned(), + display_url: parsed.into_string(), client: Client::open(url)?, }) } @@ -67,7 +73,7 @@ impl Storage for RedisCache { /// Returns the cache location. fn location(&self) -> String { - format!("Redis: {}", self.url) + format!("Redis: {}", self.display_url) } /// Returns the current cache size. This value is aquired via