Skip to content

Commit eefbece

Browse files
committed
Update Redis to v1
1 parent 87c8003 commit eefbece

File tree

4 files changed

+42
-26
lines changed

4 files changed

+42
-26
lines changed

Cargo.lock

Lines changed: 20 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ thiserror = "2.0.18"
7070
rand = "0.9.2"
7171
unsync = "0.1.2"
7272
itertools = "0.14.0"
73-
redis = { version = "0.32.7", default-features = false, features = ["smol-comp"] }
73+
redis = { version = "1.0.3", default-features = false, features = ["smol-comp"] }
7474
anyhow = { version = "1.0.101", features = ["backtrace"] }
7575
fs2 = "0.4.3"
7676

libs/tc-testutils/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ paho-mqtt = { version = "0.13.3", default-features = false, features = [
3636
"bundled",
3737
"ssl",
3838
] }
39-
redis = { version = "0.32.5", features = ["smol-comp"] }
40-
redis-macros = "0.5.6"
39+
redis = { version = "1.0.3", features = ["smol-comp"] }
40+
redis-macros = "1.0.1"
4141
anyhow = { version = "1.0.101", features = ["backtrace"] }
4242
# unsync = "0.1.2"
4343
smol = "2.0.2"

src/core/values.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55

66
use anyhow::anyhow;
77
use ecow::{EcoString, EcoVec};
8-
use redis::{FromRedisValue, RedisResult, ToRedisArgs};
8+
use redis::{FromRedisValue, ToRedisArgs, ToSingleRedisArg};
99
use serde::de::{self, Deserialize, Deserializer, MapAccess, SeqAccess, Visitor};
1010
use serde::ser::{Serialize, SerializeMap, SerializeSeq, Serializer};
1111
use serde_json::Value as JValue;
@@ -51,36 +51,38 @@ impl ToRedisArgs for Value {
5151
}
5252
}
5353

54+
// Note: Redis docs say: "This should be implemented only for types that are
55+
// serialized into exactly one value, otherwise the compiler can't ensure
56+
// the correctness of some commands."
57+
// This currently holds for the implementation of Value, but we should keep an eye out.
58+
impl ToSingleRedisArg for Value {}
59+
5460
impl FromRedisValue for Value {
55-
fn from_redis_value(v: &redis::Value) -> RedisResult<Self> {
61+
fn from_redis_value(v: redis::Value) -> Result<Self, redis::ParsingError> {
5662
match v {
5763
redis::Value::BulkString(bytes) => {
58-
let s = std::str::from_utf8(bytes).map_err(|_| {
59-
redis::RedisError::from((redis::ErrorKind::TypeError, "Invalid UTF-8"))
64+
let s = std::str::from_utf8(&bytes).map_err(|e| {
65+
redis::ParsingError::from(format!("Invalid UTF-8 in BulkString: {:?}", e))
6066
})?;
6167

62-
serde_json5::from_str(s).map_err(|_e| {
63-
redis::RedisError::from((
64-
redis::ErrorKind::TypeError,
65-
"Response type not deserializable to Value with serde_json5",
66-
format!(
67-
"(response was {:?})",
68-
redis::Value::BulkString(bytes.clone())
69-
),
68+
serde_json5::from_str(s).map_err(|e| {
69+
redis::ParsingError::from(format!(
70+
"BulkString not deserializable to Value with serde_json5: {}",
71+
e
7072
))
7173
})
7274
}
7375
redis::Value::Array(values) => {
7476
let list: Result<Vec<Value>, _> =
75-
values.iter().map(Value::from_redis_value).collect();
77+
values.iter().map(Value::from_redis_value_ref).collect();
7678
Ok(Value::List(list?.into()))
7779
}
7880
redis::Value::Nil => Ok(Value::Unit),
79-
redis::Value::Int(i) => Ok(Value::Int(*i)),
81+
redis::Value::Int(i) => Ok(Value::Int(i)),
8082
redis::Value::SimpleString(s) => Ok(Value::Str(s.clone().into())),
81-
_ => Err(redis::RedisError::from((
82-
redis::ErrorKind::TypeError,
83-
"Response type not deserializable to Value",
83+
_ => Err(redis::ParsingError::from(std::format!(
84+
"Unsupported Redis value type for Value deserialization: {:?}",
85+
v
8486
))),
8587
}
8688
}

0 commit comments

Comments
 (0)