Skip to content

Commit

Permalink
Merge updates from upstream. (#67)
Browse files Browse the repository at this point in the history
* Disable JSON module tests for redis 6.2.4. (redis-rs#980)

This happens due to a consistent crash -
RedisJSON/RedisJSON#1124

* Implement `FromRedisValue` for `Box<[T]>` and `Arc<[T]>` (redis-rs#799)

* Update minimal rust version to 1.6.5 (redis-rs#982)

It's required by regex v1.10.2.
https://github.com/redis-rs/redis-rs/actions/runs/6760188489/job/18373652560?pr=981

* Support Mutual TLS (redis-rs#858)

Add support for mutual TLS. Enable specifying client
certificate and key and (optional) root certificate.

* changing timeouts from usize and isize to f64 (redis-rs#988)

Co-authored-by: Eythor Helgason <[email protected]>

* Accept iterator at `ClusterClient` initialization (redis-rs#987)

* Prefer routing to primary in a transaction. (redis-rs#986)

* Rename route_pipeline to route_for_pipeline.

There are 2 `route_pipeline` functions in the file, so we change one to
avoid confusion.

* Prefer routing to primary in a transaction.

* CrossSlot error on pipeline with many routes.

* Sync Pub/Sub - cache received pub/sub messages. (redis-rs#910)

When sending subscibre/unsubscribe messages to the server, the pub/sub
client might receive messages that it can mistake to be the response,
and not return to the next `get_message` call. This fix ensures that
pub/sub messages will be queued until the next `get_message` call, so
that no message will be missed.

* Fix sync cluster behavior with transactions. (redis-rs#983)

The leading MULTI prevents the transaction from being properly routed.
In order to route the request correctly, we drop the leading MULTI from
the routable.

* Release redis 0.23.4 / redis-test 0.2.4 (redis-rs#992)

* Tests: Add retries to test cluster creation (redis-rs#994)

* Revert redis-test versioning changes (redis-rs#993)

Publishing to crates.io without the version specification
is currently not possible. Reverting these changes for now
until we have a better solution/workaround.

* Fix features for `load_native_certs`. (redis-rs#996)

The directive now matches the directives wrapping `load_native_certs`'s
`use` statements. This would fail compilation for anyone accidentally
using the "tls" feature with rustls.

* Bump aHash to v0.8.6 (redis-rs#966)

* Update Command expiration values to be an appropriate type (redis-rs#589)

This change updates expiration values provided to some commands in the
`Command` trait to be of type `i64` or `u64` where appropriate,
replacing the previously used `usize` type.

More specifically, the commands that are updated are

- SETEX, PSETEX
  - Expiration value changed from `usize` to `u64`
- EXPIRE, PEXPIRE, EXPIREAT, PEXPIREAT
  - Expiration value changed from `usize` to `i64`

For the `*SETEX` commands, there is no mention of supporting negative
values. And indeed, providing a negative value through redis-cli returns
an error message.

For the `*EXPIRE*` commands, I couldn't find the paragraph in the docs
referenced in redis-rs#575, nor any other mention that the commands accept a
negative expiration argument. However, in testing with redis-cli it
seems a negative expiration value is valid and in checking the code I
found it to confirm these observations. See [here][code1] and
[here][code2].

Note that this is a breaking change.

[code1]: https://github.com/redis/redis/blob/e3ef73dc2a557232c60c732705e8e6ff2050eba9/src/expire.c#L570-L571
[code2]: https://github.com/redis/redis/blob/e3ef73dc2a557232c60c732705e8e6ff2050eba9/src/expire.c#L483-L491

* Fix StreamId::contains_key signature (redis-rs#783)

* Order in usage of ClusterParams. (redis-rs#997)

* Move `tls_params` into `ClusterParams`.

The two objects are used together, so it makes sense to join them.

* Cluster: Contain `ClusterParams` internally.

This matches the async cluster's structure, and ensures that fields that
are added to `ClusterParams` are automatically added to the sync cluster

* Release redis 0.24.0 / redis-test 0.3.0 (redis-rs#998)

---------

Co-authored-by: Jacob O'Toole <[email protected]>
Co-authored-by: spaceangel <[email protected]>
Co-authored-by: eythorhel19 <[email protected]>
Co-authored-by: Eythor Helgason <[email protected]>
Co-authored-by: Ruan Petterson <[email protected]>
Co-authored-by: James Lucas <[email protected]>
Co-authored-by: aumetra <[email protected]>
Co-authored-by: Josh Leeb-du Toit <[email protected]>
Co-authored-by: Ayush <[email protected]>
  • Loading branch information
10 people authored Dec 7, 2023
1 parent 6ea685c commit eb8d19d
Show file tree
Hide file tree
Showing 34 changed files with 1,552 additions and 219 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The crate is called `redis` and you can depend on it via cargo:

```ini
[dependencies]
redis = "0.23.3"
redis = "0.24.0"
```

Documentation on the library can be found at
Expand Down Expand Up @@ -59,10 +59,10 @@ To enable asynchronous clients, enable the relevant feature in your Cargo.toml,

```
# if you use tokio
redis = { version = "0.23.3", features = ["tokio-comp"] }
redis = { version = "0.24.0", features = ["tokio-comp"] }
# if you use async-std
redis = { version = "0.23.3", features = ["async-std-comp"] }
redis = { version = "0.24.0", features = ["async-std-comp"] }
```

## TLS Support
Expand All @@ -73,25 +73,25 @@ Currently, `native-tls` and `rustls` are supported.
To use `native-tls`:

```
redis = { version = "0.23.3", features = ["tls-native-tls"] }
redis = { version = "0.24.0", features = ["tls-native-tls"] }
# if you use tokio
redis = { version = "0.23.3", features = ["tokio-native-tls-comp"] }
redis = { version = "0.24.0", features = ["tokio-native-tls-comp"] }
# if you use async-std
redis = { version = "0.23.3", features = ["async-std-native-tls-comp"] }
redis = { version = "0.24.0", features = ["async-std-native-tls-comp"] }
```

To use `rustls`:

```
redis = { version = "0.23.3", features = ["tls-rustls"] }
redis = { version = "0.24.0", features = ["tls-rustls"] }
# if you use tokio
redis = { version = "0.23.3", features = ["tokio-rustls-comp"] }
redis = { version = "0.24.0", features = ["tokio-rustls-comp"] }
# if you use async-std
redis = { version = "0.23.3", features = ["async-std-rustls-comp"] }
redis = { version = "0.24.0", features = ["async-std-rustls-comp"] }
```

With `rustls`, you can add the following feature flags on top of other feature flags to enable additional features:
Expand All @@ -117,7 +117,7 @@ let client = redis::Client::open("rediss://127.0.0.1/#insecure")?;

Support for Redis Cluster can be enabled by enabling the `cluster` feature in your Cargo.toml:

`redis = { version = "0.23.3", features = [ "cluster"] }`
`redis = { version = "0.24.0", features = [ "cluster"] }`

Then you can simply use the `ClusterClient`, which accepts a list of available nodes. Note
that only one node in the cluster needs to be specified when instantiating the client, though
Expand All @@ -140,7 +140,7 @@ fn fetch_an_integer() -> String {
Async Redis Cluster support can be enabled by enabling the `cluster-async` feature, along
with your preferred async runtime, e.g.:

`redis = { version = "0.23.3", features = [ "cluster-async", "tokio-std-comp" ] }`
`redis = { version = "0.24.0", features = [ "cluster-async", "tokio-std-comp" ] }`

```rust
use redis::cluster::ClusterClient;
Expand All @@ -160,7 +160,7 @@ async fn fetch_an_integer() -> String {

Support for the RedisJSON Module can be enabled by specifying "json" as a feature in your Cargo.toml.

`redis = { version = "0.23.3", features = ["json"] }`
`redis = { version = "0.24.0", features = ["json"] }`

Then you can simply import the `JsonCommands` trait which will add the `json` commands to all Redis Connections (not to be confused with just `Commands` which only adds the default commands)

Expand Down
3 changes: 3 additions & 0 deletions redis-test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 0.3.0 (2023-12-05)
* Track redis 0.24.0 release

### 0.2.3 (2023-09-01)

* Track redis 0.23.3 release
Expand Down
8 changes: 4 additions & 4 deletions redis-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[package]
name = "redis-test"
version = "0.2.3"
version = "0.3.0"
edition = "2021"
description = "Testing helpers for the `redis` crate"
homepage = "https://github.com/redis-rs/redis-rs"
repository = "https://github.com/redis-rs/redis-rs"
documentation = "https://docs.rs/redis-test"
license = "BSD-3-Clause"
rust-version = "1.63"
rust-version = "1.65"

[lib]
bench = false

[dependencies]
redis = { path = "../redis" }
redis = { version = "0.24.0", path = "../redis" }

bytes = { version = "1", optional = true }
futures = { version = "0.3", optional = true }
Expand All @@ -22,5 +22,5 @@ futures = { version = "0.3", optional = true }
aio = ["futures", "redis/aio"]

[dev-dependencies]
redis = { path = "../redis", features = ["aio", "tokio-comp"] }
redis = { version = "0.24.0", path = "../redis", features = ["aio", "tokio-comp"] }
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread", "time"] }
45 changes: 45 additions & 0 deletions redis/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
### 0.24.0 (2023-12-05)

#### Features
* **Breaking change**: Support Mutual TLS ([#858](https://github.com/redis-rs/redis-rs/pull/858) @sp-angel)
* Implement `FromRedisValue` for `Box<[T]>` and `Arc<[T]>` ([#799](https://github.com/redis-rs/redis-rs/pull/799) @JOT85)
* Sync Cluster: support multi-slot operations. ([#967](https://github.com/redis-rs/redis-rs/pull/967))
* Execute multi-node requests using try_request. ([#919](https://github.com/redis-rs/redis-rs/pull/919))
* Sorted set blocking commands ([#962](https://github.com/redis-rs/redis-rs/pull/962) @gheorghitamutu)
* Allow passing routing information to cluster. ([#899](https://github.com/redis-rs/redis-rs/pull/899))
* Add `tcp_nodelay` feature ([#941](https://github.com/redis-rs/redis-rs/pull/941) @PureWhiteWu)
* Add support for multi-shard commands. ([#900](https://github.com/redis-rs/redis-rs/pull/900))

#### Changes
* Order in usage of ClusterParams. ([#997](https://github.com/redis-rs/redis-rs/pull/997))
* **Breaking change**: Fix StreamId::contains_key signature ([#783](https://github.com/redis-rs/redis-rs/pull/783) @Ayush1325)
* **Breaking change**: Update Command expiration values to be an appropriate type ([#589](https://github.com/redis-rs/redis-rs/pull/589) @joshleeb)
* **Breaking change**: Bump aHash to v0.8.6 ([#966](https://github.com/redis-rs/redis-rs/pull/966) @aumetra)
* Fix features for `load_native_certs`. ([#996](https://github.com/redis-rs/redis-rs/pull/996))
* Revert redis-test versioning changes ([#993](https://github.com/redis-rs/redis-rs/pull/993))
* Tests: Add retries to test cluster creation ([#994](https://github.com/redis-rs/redis-rs/pull/994))
* Fix sync cluster behavior with transactions. ([#983](https://github.com/redis-rs/redis-rs/pull/983))
* Sync Pub/Sub - cache received pub/sub messages. ([#910](https://github.com/redis-rs/redis-rs/pull/910))
* Prefer routing to primary in a transaction. ([#986](https://github.com/redis-rs/redis-rs/pull/986))
* Accept iterator at `ClusterClient` initialization ([#987](https://github.com/redis-rs/redis-rs/pull/987) @ruanpetterson)
* **Breaking change**: Change timeouts from usize and isize to f64 ([#988](https://github.com/redis-rs/redis-rs/pull/988) @eythorhel19)
* Update minimal rust version to 1.6.5 ([#982](https://github.com/redis-rs/redis-rs/pull/982))
* Disable JSON module tests for redis 6.2.4. ([#980](https://github.com/redis-rs/redis-rs/pull/980))
* Add connection string examples ([#976](https://github.com/redis-rs/redis-rs/pull/976) @NuclearOreo)
* Move response policy into multi-node routing. ([#952](https://github.com/redis-rs/redis-rs/pull/952))
* Added functions that allow tests to check version. ([#963](https://github.com/redis-rs/redis-rs/pull/963))
* Fix XREADGROUP command ordering as per Redis Docs, and compatibility with Upstash Redis ([#960](https://github.com/redis-rs/redis-rs/pull/960) @prabhpreet)
* Optimize make_pipeline_results by pre-allocate memory ([#957](https://github.com/redis-rs/redis-rs/pull/957) @PureWhiteWu)
* Run module tests sequentially. ([#956](https://github.com/redis-rs/redis-rs/pull/956))
* Log cluster creation output in tests. ([#955](https://github.com/redis-rs/redis-rs/pull/955))
* CI: Update and use better maintained github actions. ([#954](https://github.com/redis-rs/redis-rs/pull/954))
* Call CLIENT SETINFO on new connections. ([#945](https://github.com/redis-rs/redis-rs/pull/945))
* Deprecate functions that erroneously use `tokio` in their name. ([#913](https://github.com/redis-rs/redis-rs/pull/913))
* CI: Increase timeouts and use newer redis. ([#949](https://github.com/redis-rs/redis-rs/pull/949))
* Remove redis version from redis-test. ([#943](https://github.com/redis-rs/redis-rs/pull/943))

### 0.23.4 (2023-11-26)
**Yanked** -- Inadvertently introduced breaking changes (sorry!). The changes in this tag
have been pushed to 0.24.0.

### 0.23.3 (2023-09-01)

Note that this release fixes a small regression in async Redis Cluster handling of the `PING` command.
Expand All @@ -8,6 +52,7 @@ will again return a single response instead of an array.
* Add `key_type` command ([#933](https://github.com/redis-rs/redis-rs/pull/933) @bruaba)
* Async cluster: Group responses by response_policy. ([#888](https://github.com/redis-rs/redis-rs/pull/888))


#### Fixes
* Remove unnecessary heap allocation ([#939](https://github.com/redis-rs/redis-rs/pull/939) @thechampagne)
* Sentinel tests: Ensure no ports are used twice ([#915](https://github.com/redis-rs/redis-rs/pull/915))
Expand Down
10 changes: 6 additions & 4 deletions redis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "redis"
version = "0.23.3"
version = "0.24.0"
keywords = ["redis", "database"]
description = "Redis driver for Rust."
homepage = "https://github.com/redis-rs/redis-rs"
repository = "https://github.com/redis-rs/redis-rs"
documentation = "https://docs.rs/redis"
license = "BSD-3-Clause"
edition = "2021"
rust-version = "1.63"
rust-version = "1.65"
readme = "../README.md"

[package.metadata.docs.rs]
Expand Down Expand Up @@ -79,13 +79,15 @@ webpki-roots = { version = "0.23.0", optional = true }
rustls-native-certs = { version = "0.6.2", optional = true }
tokio-rustls = { version = "0.24.0", optional = true }
futures-rustls = { version = "0.24.0", optional = true }
rustls-webpki = { version = "0.101", optional = true }
rustls-pemfile = { version = "1.0", optional = true }

# Only needed for RedisJSON Support
serde = { version = "1.0.82", optional = true }
serde_json = { version = "1.0.82", optional = true }

# Optional aHash support
ahash = { version = "0.7.6", optional = true }
ahash = { version = "0.8.6", optional = true }

tracing = "0.1"
futures-time = { version = "3.0.0", optional = true }
Expand All @@ -100,7 +102,7 @@ json = ["serde", "serde/derive", "serde_json"]
cluster = ["crc16", "rand", "derivative"]
script = ["sha1_smol"]
tls-native-tls = ["native-tls"]
tls-rustls = ["rustls", "rustls-native-certs"]
tls-rustls = ["rustls", "rustls-native-certs", "rustls-webpki", "rustls-pemfile"]
tls-rustls-insecure = ["tls-rustls", "rustls/dangerous_configuration"]
tls-rustls-webpki-roots = ["tls-rustls", "webpki-roots"]
async-std-comp = ["aio", "async-std", "backoff-std-async"]
Expand Down
9 changes: 6 additions & 3 deletions redis/benches/bench_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ fn bench_cluster_setup(c: &mut Criterion) {

#[allow(dead_code)]
fn bench_cluster_read_from_replicas_setup(c: &mut Criterion) {
let cluster = TestClusterContext::new_with_cluster_client_builder(6, 1, |builder| {
builder.read_from_replicas()
});
let cluster = TestClusterContext::new_with_cluster_client_builder(
6,
1,
|builder| builder.read_from_replicas(),
false,
);
cluster.wait_for_cluster_up();

let mut con = cluster.connection();
Expand Down
9 changes: 8 additions & 1 deletion redis/src/aio/async_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ async fn connect_tcp(addr: &SocketAddr) -> io::Result<TcpStream> {
Ok(socket)
}
}
#[cfg(feature = "tls-rustls")]
use crate::tls::TlsConnParams;

#[cfg(all(feature = "tls-native-tls", not(feature = "tls-rustls")))]
use crate::connection::TlsConnParams;

pin_project_lite::pin_project! {
/// Wraps the async_std `AsyncRead/AsyncWrite` in order to implement the required the tokio traits
Expand Down Expand Up @@ -200,6 +205,7 @@ impl RedisRuntime for AsyncStd {
hostname: &str,
socket_addr: SocketAddr,
insecure: bool,
tls_params: &Option<TlsConnParams>,
) -> RedisResult<Self> {
let tcp_stream = connect_tcp(&socket_addr).await?;
let tls_connector = if insecure {
Expand All @@ -221,10 +227,11 @@ impl RedisRuntime for AsyncStd {
hostname: &str,
socket_addr: SocketAddr,
insecure: bool,
tls_params: &Option<TlsConnParams>,
) -> RedisResult<Self> {
let tcp_stream = connect_tcp(&socket_addr).await?;

let config = create_rustls_config(insecure)?;
let config = create_rustls_config(insecure, tls_params.clone())?;
let tls_connector = TlsConnector::from(Arc::new(config));

Ok(tls_connector
Expand Down
5 changes: 3 additions & 2 deletions redis/src/aio/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,19 @@ pub(crate) async fn connect_simple<T: RedisRuntime>(
ref host,
port,
insecure,
ref tls_params,
} => {
if let Some(socket_addr) = _socket_addr {
return Ok::<_, RedisError>((
<T>::connect_tcp_tls(host, socket_addr, insecure).await?,
<T>::connect_tcp_tls(host, socket_addr, insecure, tls_params).await?,
Some(socket_addr.ip()),
));
}
let socket_addrs = get_socket_addrs(host, port).await?;
select_ok(socket_addrs.map(|socket_addr| {
Box::pin(async move {
Ok::<_, RedisError>((
<T>::connect_tcp_tls(host, socket_addr, insecure).await?,
<T>::connect_tcp_tls(host, socket_addr, insecure, tls_params).await?,
Some(socket_addr.ip()),
))
})
Expand Down
7 changes: 7 additions & 0 deletions redis/src/aio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ use std::pin::Pin;
#[cfg_attr(docsrs, doc(cfg(feature = "async-std-comp")))]
pub mod async_std;

#[cfg(feature = "tls-rustls")]
use crate::tls::TlsConnParams;

#[cfg(all(feature = "tls-native-tls", not(feature = "tls-rustls")))]
use crate::connection::TlsConnParams;

/// Enables the tokio compatibility
#[cfg(feature = "tokio-comp")]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio-comp")))]
Expand All @@ -32,6 +38,7 @@ pub(crate) trait RedisRuntime: AsyncStream + Send + Sync + Sized + 'static {
hostname: &str,
socket_addr: SocketAddr,
insecure: bool,
tls_params: &Option<TlsConnParams>,
) -> RedisResult<Self>;

/// Performs a UNIX connection
Expand Down
10 changes: 9 additions & 1 deletion redis/src/aio/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ use tokio_rustls::{client::TlsStream, TlsConnector};
#[cfg(all(feature = "tokio-native-tls-comp", not(feature = "tokio-rustls-comp")))]
use tokio_native_tls::TlsStream;

#[cfg(feature = "tokio-rustls-comp")]
use crate::tls::TlsConnParams;

#[cfg(all(feature = "tokio-native-tls-comp", not(feature = "tls-rustls")))]
use crate::connection::TlsConnParams;

#[cfg(unix)]
use super::Path;

Expand Down Expand Up @@ -125,6 +131,7 @@ impl RedisRuntime for Tokio {
hostname: &str,
socket_addr: SocketAddr,
insecure: bool,
_: &Option<TlsConnParams>,
) -> RedisResult<Self> {
let tls_connector: tokio_native_tls::TlsConnector = if insecure {
TlsConnector::builder()
Expand All @@ -147,8 +154,9 @@ impl RedisRuntime for Tokio {
hostname: &str,
socket_addr: SocketAddr,
insecure: bool,
tls_params: &Option<TlsConnParams>,
) -> RedisResult<Self> {
let config = create_rustls_config(insecure)?;
let config = create_rustls_config(insecure, tls_params.clone())?;
let tls_connector = TlsConnector::from(Arc::new(config));

Ok(tls_connector
Expand Down
Loading

0 comments on commit eb8d19d

Please sign in to comment.