Skip to content
Merged
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
10 changes: 9 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ jobs:
- name: Run clippy
run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings

# A build without TLS, or without any of docket-rs's features, is one
# that users can choose.
- name: Run clippy without default features
run: cargo clippy -p docket-rs --all-targets --no-default-features --locked -- -D warnings

- name: Build the docs
env:
RUSTDOCFLAGS: -D warnings
Expand Down Expand Up @@ -79,13 +84,16 @@ jobs:
name: Rust coverage
runs-on: ubuntu-26.04
timeout-minutes: 20
# Coverage runs on nightly, where `coverage(off)` works. This overrides
# the release that rust/rust-toolchain.toml pins.
env:
RUSTUP_TOOLCHAIN: nightly
defaults:
run:
working-directory: rust
steps:
- uses: actions/checkout@v7

# Coverage runs on nightly, where `coverage(off)` works.
- uses: dtolnay/rust-toolchain@nightly
with:
components: llvm-tools-preview
Expand Down
22 changes: 2 additions & 20 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ percent-encoding = "2.3.2"
proc-macro2 = "1.0.107"
quote = "1.0.47"
rand = "0.10.3"
redis = "1.7.1"
redis = { version = "1.7.1", default-features = false }
rstest = "0.27.0"
rustls = { version = "0.23", default-features = false }
serde = "1.0.229"
serde_json = "1.0.151"
syn = "3.0.6"
Expand Down
8 changes: 7 additions & 1 deletion rust/docket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ include = ["src/**", "lua/*.lua", "LICENSE", "README.md"]
name = "docket"

[features]
default = ["tls"]
# docket::cli: a worker's command-line options for an application's own CLI.
cli = ["dep:clap", "tokio/signal", "prometheus"]
# memory:// runs the in-process engine in src/memory, for users' test suites.
memory = ["dep:mlua", "dep:parking_lot", "dep:bytes", "dep:ordered-float", "dep:sha1"]
# rediss:// connections, through rustls with its ring crypto backend.
tls = ["redis/tokio-rustls-comp", "redis/tls-rustls-webpki-roots", "dep:rustls"]
# docket::prometheus: serves the metrics in the Prometheus text format. It
# reads them on demand, through the SDK's custom reader.
prometheus = [
Expand All @@ -33,7 +36,7 @@ chrono-tz.workspace = true
clap = { workspace = true, features = ["derive", "env"], optional = true }
croner.workspace = true
docket-rs-macros.workspace = true
redis = { workspace = true, features = ["aio", "tokio-comp", "tokio-rustls-comp", "tls-rustls-webpki-roots", "script", "streams", "cluster-async", "sentinel", "token-based-authentication"] }
redis = { workspace = true, features = ["aio", "tokio-comp", "script", "streams", "cluster-async", "sentinel", "token-based-authentication"] }
futures.workspace = true
gethostname.workspace = true
opentelemetry = { workspace = true, features = ["trace", "metrics"] }
Expand All @@ -54,6 +57,9 @@ mlua = { workspace = true, features = ["lua54", "send", "vendored"], optional =
ordered-float = { workspace = true, optional = true }
parking_lot = { workspace = true, optional = true }
sha1 = { workspace = true, optional = true }
# redis turns off rustls's default features, which leaves rustls no crypto
# backend; the tls feature gives it ring.
rustls = { workspace = true, features = ["ring", "std", "tls12"], optional = true }

[dev-dependencies]
futures-util.workspace = true
Expand Down
12 changes: 12 additions & 0 deletions rust/docket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ A docket URL is `redis://`, `rediss://`, `unix://`, `redis+cluster://`,
with Redis 6.2 and 8.10, Redis 8.10 in cluster mode, with ACLs, and behind
Sentinel, and Valkey 8.0 and 9.1.

`rediss://`, `rediss+cluster://`, and `rediss+sentinel://` connect over TLS
through rustls, with its `ring` crypto backend. The default `tls` feature
brings both. If another crate in your build turns on rustls's `aws-lc-rs`
backend too, rustls cannot pick one, so call
`rustls::crypto::CryptoProvider::install_default` before connecting. Without
TLS, turn off the default features:

```toml
[dependencies]
docket-rs = { version = "0.2", default-features = false }
```

`memory://`, behind the `memory` feature, runs an in-process Redis, so your
own tests need no server. Each `memory://` URL keeps its data for the life of
the process, as in pydocket, so a docket opened again on a URL finds what the
Expand Down
11 changes: 10 additions & 1 deletion rust/docket/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ enum Kind {

impl Backend {
pub fn open(url: &str, credentials: Option<Provider>) -> Result<Self> {
#[cfg(not(feature = "tls"))]
if url.starts_with("rediss") {
return Err(crate::Error::url(
url,
"rediss:// needs docket's tls feature",
));
}
let kind = match url::parse(url)? {
Target::Standalone(url) => Client::open(url).map(Kind::Standalone),
Target::Cluster(node) => Client::open(node.as_str()).and_then(|pubsub| {
Expand Down Expand Up @@ -84,7 +91,9 @@ impl Backend {
Kind::Standalone(client) | Kind::Cluster { pubsub: client, .. } => {
credentials::has_credentials(client)
}
_ => false,
Kind::Sentinel(_) => false,
#[cfg(feature = "memory")]
Kind::Memory(_) => false,
};
if credentials.is_some() && url_credentials {
return Err(crate::Error::url(
Expand Down
12 changes: 12 additions & 0 deletions rust/docket/src/connection/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ fn a_sentinel_client_builds_without_connecting(
assert!(sentinel_client(sentinel_url(tls, credentials)).is_ok());
}

/// rustls has no crypto backend of its own, so without the one the `tls`
/// feature brings, a TLS connect panics before it reaches the network.
#[cfg(feature = "tls")]
#[tokio::test]
async fn a_tls_connect_reaches_the_network() {
let backend = Backend::open("rediss://127.0.0.1:1", None).unwrap();
let Err(error) = backend.connect().await else {
panic!("nothing listens on port 1");
};
assert!(error.is_connection_refusal(), "{error}");
}

/// The Redis the suite runs against, or an in-process one.
fn url() -> String {
std::env::var("DOCKET_TEST_URL")
Expand Down
2 changes: 1 addition & 1 deletion rust/docket/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Context {
}
}

#[cfg(test)]
#[cfg(all(test, feature = "memory"))]
impl Context {
/// A context for a run of `function` with empty arguments, for unit
/// tests of handlers and hooks.
Expand Down
7 changes: 4 additions & 3 deletions rust/docket/src/docket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ impl Docket {
/// Connects to the docket `name` in the Redis at `url`, with the default
/// settings.
///
/// `url` takes the same forms as in pydocket: `redis://`, `rediss://`,
/// `unix://`, `redis+cluster://`, `redis+sentinel://host:port/service`,
/// and, with the `memory` feature, `memory://` for an in-process Redis.
/// `url` takes the same forms as in pydocket: `redis://`,
/// `redis+cluster://`, `redis+sentinel://host:port/service`, their
/// `rediss` forms with the default `tls` feature, `unix://`, and, with
/// the `memory` feature, `memory://` for an in-process Redis.
pub async fn connect(name: impl Into<String>, url: impl Into<String>) -> Result<Self> {
Self::builder(name, url).connect().await
}
Expand Down
3 changes: 3 additions & 0 deletions rust/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.99"
components = ["rustfmt", "clippy"]