-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement MVP redis-config crate
feat: Implement MVP redis-config crate feat: Add CI feat: Add docs & tests
- Loading branch information
Showing
14 changed files
with
939 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: cargo | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
- package-ecosystem: github-actions | ||
directory: "/" | ||
schedule: | ||
interval: daily |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
**Note: for support questions, please use stackoverflow**. This repository's issues are reserved for feature requests and bug reports. | ||
|
||
* **I'm submitting a ...** | ||
- [ ] bug report | ||
- [ ] feature request | ||
- [ ] support request => Please do not submit support request here, see note at the top of this template. | ||
|
||
|
||
* **Do you want to request a *feature* or report a *bug*?** | ||
|
||
|
||
|
||
* **What is the current behavior?** | ||
|
||
|
||
|
||
* **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem** via | ||
https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5). | ||
|
||
|
||
|
||
* **What is the expected behavior?** | ||
|
||
|
||
|
||
* **What is the motivation / use case for changing the behavior?** | ||
|
||
|
||
|
||
* **Please tell us about your environment:** | ||
|
||
- Version: 2.0.0-beta.X | ||
- Rust compiler version | ||
|
||
|
||
* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc) |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
* **Please check if the PR fulfills these requirements** | ||
- [ ] The commit message follows our guidelines | ||
- [ ] Tests for the changes have been added (for bug fixes / features) | ||
- [ ] Docs have been added / updated (for bug fixes / features) | ||
|
||
|
||
* **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...) | ||
|
||
|
||
|
||
* **What is the current behavior?** (You can also link to an open issue here) | ||
|
||
|
||
|
||
* **What is the new behavior (if this is a feature change)?** | ||
|
||
|
||
|
||
* **Does this PR introduce a breaking change?** (What changes might users need to make in their application due to this PR?) | ||
|
||
|
||
|
||
* **Other information**: |
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 |
---|---|---|
@@ -0,0 +1,137 @@ | ||
|
||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- release/* | ||
tags: | ||
- v* | ||
pull_request: | ||
branches: | ||
- master | ||
- release/* | ||
|
||
jobs: | ||
fmt: | ||
name: Fmt | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- stable | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/[email protected] | ||
|
||
- name: Install toolchain | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
components: rustfmt | ||
|
||
- name: Run cargo fmt | ||
run: cargo fmt --all -- --check | ||
|
||
clippy: | ||
needs: [fmt] | ||
name: Clippy | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- 1.73.0 | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/[email protected] | ||
|
||
- name: Install toolchain | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
components: clippy | ||
|
||
- name: Run cargo clippy | ||
run: cargo clippy --all-targets --all-features -- -D warnings -W clippy::all -W clippy::pedantic | ||
|
||
check: | ||
needs: [fmt] | ||
name: Check | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- 1.70.0 | ||
- stable | ||
- nightly | ||
|
||
steps: | ||
- name: Checkout sources | ||
uses: actions/[email protected] | ||
|
||
- name: Install toolchain | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
|
||
- name: Run cargo check | ||
if: matrix.rust != 'nightly' | ||
run: cargo check --all-features | ||
|
||
- name: Run cargo check (nightly) | ||
if: matrix.rust == 'nightly' | ||
continue-on-error: true | ||
run: cargo check --all-features | ||
|
||
test: | ||
needs: [check, clippy] | ||
name: Integration Tests | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- 1.70.0 | ||
- 1.73.0 | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/[email protected] | ||
|
||
- name: Install redis | ||
run: sudo apt-get install -y redis-tools redis-server | ||
- name: Verify that redis is up | ||
run: redis-cli ping | ||
|
||
- name: Install toolchain | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
|
||
- name: Install nextest | ||
uses: taiki-e/install-action@nextest | ||
|
||
- name: Running tests | ||
env: | ||
TEST_REDIS_URL: redis://127.0.0.1:6379 | ||
run: cargo nextest run | ||
|
||
check-examples: | ||
name: Check examples | ||
needs: [fmt] | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- 1.70.0 | ||
|
||
steps: | ||
- name: Checkout sources | ||
uses: actions/[email protected] | ||
|
||
- name: Install toolchain | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
|
||
- name: Run cargo check | ||
run: cargo check --examples |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Release-plz | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: write | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
release-plz: | ||
name: Release-plz | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Install Rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
- name: Run release-plz | ||
uses: MarcoIeni/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_API_TOKEN }} |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[package] | ||
name = "redis_config" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Daniil Trotsenko <[email protected]>"] | ||
readme = "README.md" | ||
keywords = ["config", "configuration", "settings", "redis"] | ||
categories = ["config", "redis"] | ||
documentation = "https://docs.rs/redis_config" | ||
homepage = "https://github.com/danik-tro/redis-config" | ||
repository = "https://github.com/danik-tro/redis-config" | ||
license = "MIT" | ||
description = "Implementation of Redis source as Async source for config-rs crate." | ||
rust-version = "1.70" | ||
|
||
[badges] | ||
maintence = { status = "experimental" } | ||
|
||
|
||
[dependencies] | ||
serde = { version = "1.0", features = ["derive"]} | ||
serde_json = "1.0" | ||
thiserror = "1.0" | ||
async-trait = "0.1" | ||
config = "0.13.3" | ||
redis = { version = "0.23.3", features = ["aio"], default-features = false} | ||
|
||
[features] | ||
default = ["tokio-cmp"] | ||
tokio-cmp = ["redis/tokio-comp"] | ||
async-std-comp = ["redis/async-std"] | ||
|
||
ahash = ["redis/ahash"] | ||
async-std-native-tls-comp = ["redis/async-std-native-tls-comp"] | ||
async-std-rustls-comp = ["redis/async-std-rustls-comp"] | ||
tokio-native-tls-comp = ["redis/tokio-native-tls-comp"] | ||
tokio-rustls-comp = ["redis/tokio-rustls-comp"] | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] } | ||
uuid = { version = "1.0", features = ["v4", "v7"] } | ||
uuid7 = "0.7.2" | ||
redis = { version = "0.23.3", features = ["aio", "connection-manager", "tokio-comp"], default-features = false} | ||
async-once-cell = "0.5.3" | ||
fake = { version = "2.8", features = ["derive"] } | ||
futures = "0.3" | ||
|
||
[[example]] | ||
name = "redis_key_source" | ||
|
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 |
---|---|---|
@@ -1,2 +1,63 @@ | ||
# redis-config | ||
Implementation of Redis source as Async source for config-rs crate. | ||
|
||
![Rust](https://img.shields.io/badge/rust-stable-brightgreen.svg) | ||
[![Crates.io](https://img.shields.io/crates/d/redis_config.svg)](https://crates.io/crates/redis_config) | ||
[![Docs.rs](https://docs.rs/redis_config/badge.svg)](https://docs.rs/redis_config) | ||
|
||
> Implementation of Redis source as Async source for config-rs crate. | ||
## Usage | ||
|
||
```toml | ||
# Cargo.toml | ||
|
||
[dependencies] | ||
redis_config = "*" | ||
``` | ||
|
||
### Feature flags | ||
|
||
- `tokio-comp` - enables support for tokio runtime (enabled by default) | ||
- `async-std-comp` - enables support for async-std runtime (optional) | ||
- `ahash` - enables ahash map/set support & uses ahash internally (+7-10% performance) (optional) | ||
|
||
### Examples | ||
|
||
```rust | ||
use config::builder::AsyncState; | ||
use redis_config::RedisSource; | ||
|
||
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)] | ||
struct ServerSettings { | ||
ttl: i64, | ||
path: String, | ||
} | ||
|
||
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)] | ||
struct ApplicationSettings { | ||
server: ServerSettings, | ||
} | ||
|
||
async fn get_config() -> Result<ApplicationSettings, config::ConfigError> { | ||
let config = config::ConfigBuilder::<AsyncState>::default() | ||
.add_async_source( | ||
RedisSource::try_new(SOURCE_KEY, REDIS_URL) | ||
.map_err(|err| config::ConfigError::NotFound(err.to_string()))?, | ||
) | ||
.build() | ||
.await?; | ||
config.try_deserialize() | ||
} | ||
|
||
let config = get_config().await.unwrap(); | ||
``` | ||
|
||
### More | ||
|
||
See the [documentation](https://docs.rs/redis_config) for more usage information. | ||
|
||
## License | ||
|
||
`redis_config` is primarily distributed under the terms of both the MIT license. | ||
|
||
See LICENSE-MIT for details. |
Oops, something went wrong.