Skip to content

Commit

Permalink
6.0.0 (#109)
Browse files Browse the repository at this point in the history
* doc: clean up examples, docs, tests
  • Loading branch information
aembke authored Mar 17, 2023
1 parent 5ef307a commit 46ff203
Show file tree
Hide file tree
Showing 35 changed files with 177 additions and 180 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Rework the MOVED/ASK implementation to more quickly and reliably follow cluster redirects.
* Rework the sentinel interface to more reliably handle failover scenarios.
* Fix several bugs related to detecting closed connections.
* Support the `functions` interface.
* Add `Script`, `Library`, and `Function` structs.
* Add `Message` and `MessageKind` pubsub structs.
* Add a DNS configuration interface.
Expand Down
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ doc = true
name = "fred"
test = true

[[example]]
name = "basic"
required-features = ["partial-tracing"]

[[example]]
name = "monitor"
required-features = ["monitor"]
Expand Down
61 changes: 25 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Fred
[![Crates.io](https://img.shields.io/crates/v/fred.svg)](https://crates.io/crates/fred)
[![API docs](https://docs.rs/fred/badge.svg)](https://docs.rs/fred)

An async Redis client for Rust built on Tokio and Futures.
An async Redis client for Rust.

## Example

Expand Down Expand Up @@ -42,7 +42,7 @@ async fn main() -> Result<(), RedisError> {
}
```

See the [examples](examples/README.md) for more.
See the [examples](https://github.com/aembke/fred.rs/tree/main/examples) for more.

## Features

Expand All @@ -67,38 +67,27 @@ See the [examples](examples/README.md) for more.

## Build Time Features

| Name | Default | Description |
|-------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| enable-native-tls | | Enable TLS support via [native-tls](https://crates.io/crates/native-tls). |
| enable-rustls | | Enable TLS support via [rustls](https://crates.io/crates/rustls). |
| vendored-openssl | | Enable the `native-tls/vendored` feature, if possible. |
| ignore-auth-error | x | Ignore auth errors that occur when a password is supplied but not required. |
| metrics | | Enable the metrics interface to track overall latency, network latency, and request/response sizes. |
| Name | Default | Description |
|-------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| enable-native-tls | | Enable TLS support via [native-tls](https://crates.io/crates/native-tls). |
| enable-rustls | | Enable TLS support via [rustls](https://crates.io/crates/rustls). |
| vendored-openssl | | Enable the `native-tls/vendored` feature, if possible. |
| ignore-auth-error | x | Ignore auth errors that occur when a password is supplied but not required. |
| metrics | | Enable the metrics interface to track overall latency, network latency, and request/response sizes. |
| reconnect-on-auth-error | | A NOAUTH error is treated the same as a general connection failure and the client will reconnect based on the reconnection policy. This is [recommended](https://github.com/StackExchange/StackExchange.Redis/issues/1273#issuecomment-651823824) if callers are using ElastiCache. |
| pool-prefer-active | x | Prefer connected clients over clients in a disconnected state when using the `RedisPool` interface. |
| full-tracing | | Enable full [tracing](./src/trace/README.md) support. This can emit a lot of data so a partial tracing feature is also provided. |
| partial-tracing | | Enable partial [tracing](./src/trace/README.md) support, only emitting traces for top level commands and network latency. Note: this has a non-trivial impact on performance. |
| blocking-encoding | | Use a blocking task for encoding or decoding frames. This can be useful for clients that send or receive large payloads, but will only work when used with a multi-thread Tokio runtime. |
| network-logs | | Enable TRACE level logging statements that will print out all data sent to or received from the server. These are the only logging statements that can ever contain potentially sensitive user data. |
| custom-reconnect-errors | | Enable an interface for callers to customize the types of errors that should automatically trigger reconnection logic. |
| monitor | | Enable an interface for running the `MONITOR` command. |
| sentinel-client | | Enable an interface for communicating directly with Sentinel nodes. This is not necessary to use normal Redis clients behind a sentinel layer. |
| sentinel-auth | | Enable an interface for using different authentication credentials to sentinel nodes. |
| subscriber-client | | Enable an optional subscriber client that manages channel subscription state for callers. |
| serde-json | | Enable an interface to automatically convert Redis types to JSON. |
| no-client-setname | | Disable the automatic `CLIENT SETNAME` command used to associate server logs with client logs. |
| mocks | | Enable a mocking layer interface that can be used to intercept and process commands in tests. |
| dns | | Enable an interface that allows callers to override the DNS lookup logic. |
| check-unresponsive | | Enable additional monitoring to detect unresponsive connections. |
| replicas | | [Beta] Enable an interface that routes commands to replica nodes. |


## Tests

See the [testing documentation](./tests/README.md) for more information.

**Beware: the tests will periodically run `flushall`.**

## Contributing

See the [contributing](CONTRIBUTING.md) documentation for info on adding new commands.
| pool-prefer-active | x | Prefer connected clients over clients in a disconnected state when using the `RedisPool` interface. |
| full-tracing | | Enable full [tracing](./src/trace/README.md) support. This can emit a lot of data. |
| partial-tracing | | Enable partial [tracing](./src/trace/README.md) support, only emitting traces for top level commands and network latency. |
| blocking-encoding | | Use a blocking task for encoding or decoding frames. This can be useful for clients that send or receive large payloads, but will only work when used with a multi-thread Tokio runtime. |
| network-logs | | Enable TRACE level logging statements that will print out all data sent to or received from the server. These are the only logging statements that can ever contain potentially sensitive user data. |
| custom-reconnect-errors | | Enable an interface for callers to customize the types of errors that should automatically trigger reconnection logic. |
| monitor | | Enable an interface for running the `MONITOR` command. |
| sentinel-client | | Enable an interface for communicating directly with Sentinel nodes. This is not necessary to use normal Redis clients behind a sentinel layer. |
| sentinel-auth | | Enable an interface for using different authentication credentials to sentinel nodes. |
| subscriber-client | | Enable an optional subscriber client that manages channel subscription state for callers. |
| serde-json | | Enable an interface to automatically convert Redis types to JSON. |
| no-client-setname | | Disable the automatic `CLIENT SETNAME` command used to associate server logs with client logs. |
| mocks | | Enable a mocking layer interface that can be used to intercept and process commands in tests. |
| dns | | Enable an interface that allows callers to override the DNS lookup logic. |
| check-unresponsive | | Enable additional monitoring to detect unresponsive connections. |
| replicas | | (Beta) Enable an interface that routes commands to replica nodes. |
2 changes: 1 addition & 1 deletion bin/inf_loop/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
REDIS_VERSION: "${REDIS_VERSION}"
networks:
- app-tier
entrypoint: "cargo run --release --features \"replicas debug-ids network-logs\" -- ${TEST_ARGV}"
entrypoint: "cargo run --release --features \"replicas\" -- ${TEST_ARGV}"
environment:
RUST_LOG: "${RUST_LOG}"
REDIS_VERSION: "${REDIS_VERSION}"
Expand Down
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Examples
* [Publish-Subscribe](./pubsub.rs) - Use multiple clients together with the pubsub interface in a way that survives network interruptions.
* [Blocking](./blocking.rs) - Use multiple clients with the blocking list interface.
* [Transactions](./transactions.rs) - Use the MULTI/EXEC interface on a client.
* [Pipeline](./pipeline.rs) - Use the manual pipeline interface.
* [Lua](./lua.rs) - Use the Lua scripting interface on a client.
* [Scan](./scan.rs) - Use the SCAN interface to scan and read keys.
* [Prometheus](./prometheus.rs) - Use the metrics interface with prometheus.
Expand All @@ -17,4 +18,4 @@ Examples
* [Custom](./custom.rs) - Send custom commands or operate on RESP frames.
* [DNS](./dns.rs) - Customize the DNS resolution logic.

Or check out the [tests](../tests/integration) for more examples.
Or see the [tests](../tests/integration) for more examples.
31 changes: 18 additions & 13 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
use fred::{
prelude::*,
types::{BackpressureConfig, BackpressurePolicy, PerformanceConfig, RespVersion, TlsConfig},
types::{BackpressureConfig, BackpressurePolicy, PerformanceConfig, RespVersion},
};
use futures::stream::StreamExt;
use std::{default::Default, sync::Arc};

#[cfg(feature = "mocks")]
use fred::mocks::Echo;
#[cfg(feature = "partial-tracing")]
use fred::tracing::Level;
#[cfg(any(feature = "enable-native-tls", feature = "enable-rustls"))]
use fred::types::TlsConfig;
#[cfg(feature = "partial-tracing")]
use fred::types::TracingConfig;
#[cfg(feature = "mocks")]
use std::{default::Default, sync::Arc};

#[tokio::main]
async fn main() -> Result<(), RedisError> {
pretty_env_logger::init();

let _ = RedisConfig::from_url("redis://username:[email protected]:6379/1")?;

// full configuration with default values
// full configuration with testing values
let config = RedisConfig {
fail_fast: true,
server: ServerConfig::new_centralized("127.0.0.1", 6379),
server: ServerConfig::new_centralized("redis-main", 6379),
blocking: Blocking::Block,
username: None,
password: None,
username: Some("foo".into()),
password: Some("bar".into()),
version: RespVersion::RESP2,
database: None,
#[cfg(any(feature = "enable-native-tls", feature = "enable-rustls"))]
tls: None,
#[cfg(feature = "partial-tracing")]
tracing: TracingConfig {
enabled: false,
default_tracing_level: Level::INFO,
full_tracing_level: Level::DEBUG,
enabled: false,
default_tracing_level: Level::INFO,
#[cfg(feature = "full-tracing")]
full_tracing_level: Level::DEBUG,
},
#[cfg(feature = "mocks")]
mocks: Arc::new(Echo),
};
// example showing a full kitchen sink configuration for performance tuning options
// full configuration for performance tuning options
let perf = PerformanceConfig {
// whether or not to automatically pipeline commands across tasks
auto_pipeline: true,
Expand Down Expand Up @@ -72,12 +77,12 @@ async fn main() -> Result<(), RedisError> {
let mut reconnect_rx = client.on_reconnect();

tokio::spawn(async move {
while let Some(error) = error_rx.recv().await {
while let Ok(error) = error_rx.recv().await {
println!("Client disconnected with error: {:?}", error);
}
});
tokio::spawn(async move {
while let Some(_) = reconnect_rx.recv().await {
while reconnect_rx.recv().await.is_ok() {
println!("Client reconnected.");
}
});
Expand Down
Loading

0 comments on commit 46ff203

Please sign in to comment.