Skip to content

Commit 0e40fea

Browse files
authored
feat: update redis to 0.25 (#8)
1 parent b5d5b78 commit 0e40fea

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "faststr"
3-
version = "0.2.17"
3+
version = "0.2.18"
44
authors = ["Volo Team <[email protected]>"]
55
edition = "2021"
66
description = "Faststr is a string library that reduces the cost of clone."
@@ -15,7 +15,7 @@ keywords = ["string", "str", "volo"]
1515
bytes = "1"
1616
serde = { version = "1", optional = true, default_features = false }
1717
simdutf8 = { version = "0.1", features = ["aarch64_neon"] }
18-
redis = { version = "0.24", optional = true, default_features = false }
18+
redis = { version = "0.25", optional = true, default_features = false }
1919
itoa = { version = "1", optional = true }
2020

2121
[features]

src/redis.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,21 @@ impl redis::FromRedisValue for crate::FastStr {
2727
}
2828
}
2929

30-
fn from_byte_vec(vec: &[u8]) -> Option<Vec<Self>> {
31-
#[cfg(feature = "redis-unsafe")]
32-
{
33-
let s = unsafe { Self::new_u8_slice_unchecked(vec) };
34-
Some(vec![s])
35-
}
36-
#[cfg(not(feature = "redis-unsafe"))]
37-
{
38-
let s = Self::new_u8_slice(vec);
39-
if s.is_err() {
40-
return None;
41-
}
42-
Some(vec![s.unwrap()])
30+
fn from_owned_redis_value(v: redis::Value) -> redis::RedisResult<Self> {
31+
match v {
32+
#[cfg(feature = "redis-unsafe")]
33+
redis::Value::Data(bytes) => Ok(unsafe { Self::from_vec_u8_unchecked(bytes) }),
34+
#[cfg(not(feature = "redis-unsafe"))]
35+
redis::Value::Data(bytes) => Self::from_vec_u8(bytes)
36+
.map_err(|_| (redis::ErrorKind::TypeError, "Invalid UTF8").into()),
37+
redis::Value::Nil => Ok(Self::empty()),
38+
redis::Value::Int(v) => Ok(Self::new(itoa::Buffer::new().format(v))),
39+
redis::Value::Status(s) => Ok(Self::from_string(s)),
40+
redis::Value::Okay => Ok(Self::from_static_str("OK")),
41+
_ => Err(redis::RedisError::from((
42+
redis::ErrorKind::TypeError,
43+
"Invalid response type",
44+
))),
4345
}
4446
}
4547
}

0 commit comments

Comments
 (0)