Skip to content

Commit

Permalink
Update redis to 0.26
Browse files Browse the repository at this point in the history
Co-authored-by: hzlinyiyu <hzlinyiyu@corp.netease.com>
  • Loading branch information
attila-lin and hzlinyiyu-netease committed Jul 29, 2024
1 parent 7b933c5 commit 6c361a3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 22 deletions.
4 changes: 3 additions & 1 deletion redis/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Update `redis` dependency to version `0.26`

## [0.15.1] - 2024-05-04

- Update `deadpool` dependency to version `0.12`
Expand Down Expand Up @@ -183,4 +185,4 @@ Release of 0.6 and 0.7 with the following feature backported:
[0.4.1]: https://github.com/bikeshedder/deadpool/compare/deadpool-redis-v0.4.0...deadpool-redis-v0.4.1
[0.4.0]: https://github.com/bikeshedder/deadpool/compare/deadpool-redis-v0.3.0...deadpool-redis-v0.4.0
[0.3.0]: https://github.com/bikeshedder/deadpool/compare/deadpool-redis-v0.2.0...deadpool-redis-v0.3.0
[0.2.0]: https://github.com/bikeshedder/deadpool/releases/tag/deadpool-redis-v0.2.0
[0.2.0]: https://github.com/bikeshedder/deadpool/releases/tag/deadpool-redis-v0.2.0
4 changes: 2 additions & 2 deletions redis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cluster = ["redis/cluster-async"]
deadpool = { path = "../", version = "0.12.0", default-features = false, features = [
"managed",
] }
redis = { version = "0.25", default-features = false, features = ["aio"] }
redis = { version = "0.26", default-features = false, features = ["aio"] }
serde = { package = "serde", version = "1.0", features = [
"derive",
], optional = true }
Expand All @@ -37,7 +37,7 @@ serde = { package = "serde", version = "1.0", features = [
config = { version = "0.14", features = ["json"] }
dotenvy = "0.15.0"
futures = "0.3.15"
redis = { version = "0.25", default-features = false, features = [
redis = { version = "0.26", default-features = false, features = [
"tokio-comp",
] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
8 changes: 4 additions & 4 deletions redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn main() {
let mut conn = pool.get().await.unwrap();
cmd("SET")
.arg(&["deadpool/test_key", "42"])
.query_async::<_, ()>(&mut conn)
.query_async::<()>(&mut conn)
.await.unwrap();
}
{
Expand Down Expand Up @@ -74,7 +74,7 @@ async fn main() {
let mut conn = pool.get().await.unwrap();
cmd("SET")
.arg(&["deadpool/test_key", "42"])
.query_async::<_, ()>(&mut conn)
.query_async::<()>(&mut conn)
.await.unwrap();
}
{
Expand Down Expand Up @@ -108,7 +108,7 @@ async fn main() {
let mut conn = pool.get().await.unwrap();
cmd("SET")
.arg(&["deadpool/test_key", "42"])
.query_async::<_, ()>(&mut conn)
.query_async::<()>(&mut conn)
.await.unwrap();
}
{
Expand Down Expand Up @@ -158,7 +158,7 @@ async fn main() {
let mut conn = pool.get().await.unwrap();
cmd("SET")
.arg(&["deadpool/test_key", "42"])
.query_async::<_, ()>(&mut conn)
.query_async::<()>(&mut conn)
.await.unwrap();
}
{
Expand Down
2 changes: 1 addition & 1 deletion redis/src/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl managed::Manager for Manager {
let ping_number = self.ping_number.fetch_add(1, Ordering::Relaxed).to_string();
let n = redis::cmd("PING")
.arg(&ping_number)
.query_async::<_, String>(conn)
.query_async::<String>(conn)
.await?;
if n == ping_number {
Ok(())
Expand Down
27 changes: 27 additions & 0 deletions redis/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,24 +251,51 @@ pub struct RedisConnectionInfo {

/// Optionally a password that should be used for connection.
pub password: Option<String>,

/// Version of the protocol to use.
pub protocol: ProtocolVersion,
}

/// This is a 1:1 copy of the [`redis::ProtocolVersion`] struct.
/// Enum representing the communication protocol with the server. This enum represents the types
/// of data that the server can send to the client, and the capabilities that the client can use.
#[derive(Clone, Eq, PartialEq, Default, Debug, Copy)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(crate = "serde"))]
pub enum ProtocolVersion {
/// <https://github.com/redis/redis-specifications/blob/master/protocol/RESP2.md>
#[default]
RESP2,
/// <https://github.com/redis/redis-specifications/blob/master/protocol/RESP3.md>
RESP3,
}

impl From<RedisConnectionInfo> for redis::RedisConnectionInfo {
fn from(info: RedisConnectionInfo) -> Self {
let protocol = match info.protocol {
ProtocolVersion::RESP2 => redis::ProtocolVersion::RESP2,
ProtocolVersion::RESP3 => redis::ProtocolVersion::RESP3,
};
Self {
db: info.db,
username: info.username,
password: info.password,
protocol,
}
}
}

impl From<redis::RedisConnectionInfo> for RedisConnectionInfo {
fn from(info: redis::RedisConnectionInfo) -> Self {
let protocol = match info.protocol {
redis::ProtocolVersion::RESP2 => ProtocolVersion::RESP2,
redis::ProtocolVersion::RESP3 => ProtocolVersion::RESP3,
};
Self {
db: info.db,
username: info.username,
password: info.password,
protocol,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl managed::Manager for Manager {
.ignore()
.cmd("PING")
.arg(&ping_number)
.query_async::<_, (String,)>(conn)
.query_async::<(String,)>(conn)
.await?;
if n == ping_number {
Ok(())
Expand Down
20 changes: 10 additions & 10 deletions redis/tests/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn test_aborted_command() {
// https://github.com/mitsuhiko/redis-rs/issues/489
cmd("PING")
.arg("wrong")
.query_async::<_, String>(&mut conn)
.query_async::<String>(&mut conn)
.now_or_never();
}
{
Expand All @@ -94,7 +94,7 @@ async fn test_recycled() {

cmd("CLIENT")
.arg("ID")
.query_async::<_, i64>(&mut conn)
.query_async::<i64>(&mut conn)
.await
.unwrap()
};
Expand All @@ -104,7 +104,7 @@ async fn test_recycled() {

let new_client_id = cmd("CLIENT")
.arg("ID")
.query_async::<_, i64>(&mut conn)
.query_async::<i64>(&mut conn)
.await
.unwrap();

Expand All @@ -130,13 +130,13 @@ async fn test_recycled_with_watch() {

let client_id = cmd("CLIENT")
.arg("ID")
.query_async::<_, i64>(&mut conn)
.query_async::<i64>(&mut conn)
.await
.unwrap();

cmd("WATCH")
.arg(WATCHED_KEY)
.query_async::<_, ()>(&mut conn)
.query_async::<()>(&mut conn)
.await
.unwrap();

Expand All @@ -148,7 +148,7 @@ async fn test_recycled_with_watch() {

let new_client_id = cmd("CLIENT")
.arg("ID")
.query_async::<_, i64>(&mut txn_conn)
.query_async::<i64>(&mut txn_conn)
.await
.unwrap();

Expand All @@ -161,7 +161,7 @@ async fn test_recycled_with_watch() {
// Start transaction on another key
cmd("WATCH")
.arg(TXN_KEY)
.query_async::<_, ()>(&mut txn_conn)
.query_async::<()>(&mut txn_conn)
.await
.unwrap();

Expand All @@ -172,7 +172,7 @@ async fn test_recycled_with_watch() {
cmd("SET")
.arg(WATCHED_KEY)
.arg("v")
.query_async::<_, ()>(&mut writer_conn)
.query_async::<()>(&mut writer_conn)
.await
.unwrap();
}
Expand All @@ -181,12 +181,12 @@ async fn test_recycled_with_watch() {
let txn_result = pipe()
.atomic()
.set(TXN_KEY, "foo")
.query_async::<_, Value>(&mut txn_conn)
.query_async::<Value>(&mut txn_conn)
.await
.unwrap();
assert_eq!(
txn_result,
Value::Bulk(vec![Value::Okay]),
Value::Array(vec![Value::Okay]),
"redis transaction in recycled connection aborted",
);
}
Expand Down
6 changes: 3 additions & 3 deletions redis/tests/redis_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async fn test_aborted_command() {
// https://github.com/mitsuhiko/redis-rs/issues/489
cmd("PING")
.arg("wrong")
.query_async::<_, String>(&mut conn)
.query_async::<String>(&mut conn)
.now_or_never();
}
{
Expand All @@ -99,7 +99,7 @@ async fn test_recycled() {

cmd("CLIENT")
.arg("ID")
.query_async::<_, i64>(&mut conn)
.query_async::<i64>(&mut conn)
.await
.unwrap()
};
Expand All @@ -109,7 +109,7 @@ async fn test_recycled() {

let new_client_id = cmd("CLIENT")
.arg("ID")
.query_async::<_, i64>(&mut conn)
.query_async::<i64>(&mut conn)
.await
.unwrap();

Expand Down

0 comments on commit 6c361a3

Please sign in to comment.