diff --git a/Cargo.lock b/Cargo.lock index 2b14a59..6fece5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,7 +190,7 @@ checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] name = "faststr" -version = "0.2.17" +version = "0.2.18" dependencies = [ "bytes", "criterion", @@ -384,9 +384,9 @@ dependencies = [ [[package]] name = "redis" -version = "0.24.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c580d9cbbe1d1b479e8d67cf9daf6a62c957e6846048408b80b43ac3f6af84cd" +checksum = "3268dab7fe8f1d136b3c4367bc230383dc2c357f8e305ee898fa3beacddaf00d" dependencies = [ "combine", "itoa", diff --git a/Cargo.toml b/Cargo.toml index 9ad5372..4660e28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "faststr" -version = "0.2.17" +version = "0.2.18" authors = ["Volo Team "] edition = "2021" description = "Faststr is a string library that reduces the cost of clone." @@ -15,7 +15,7 @@ keywords = ["string", "str", "volo"] bytes = "1" serde = { version = "1", optional = true, default_features = false } simdutf8 = { version = "0.1", features = ["aarch64_neon"] } -redis = { version = "0.24", optional = true, default_features = false } +redis = { version = "0.25", optional = true, default_features = false } itoa = { version = "1", optional = true } [features] diff --git a/src/redis.rs b/src/redis.rs index 4a95dd6..4dc56fc 100644 --- a/src/redis.rs +++ b/src/redis.rs @@ -27,19 +27,21 @@ impl redis::FromRedisValue for crate::FastStr { } } - fn from_byte_vec(vec: &[u8]) -> Option> { - #[cfg(feature = "redis-unsafe")] - { - let s = unsafe { Self::new_u8_slice_unchecked(vec) }; - Some(vec![s]) - } - #[cfg(not(feature = "redis-unsafe"))] - { - let s = Self::new_u8_slice(vec); - if s.is_err() { - return None; - } - Some(vec![s.unwrap()]) + fn from_owned_redis_value(v: redis::Value) -> redis::RedisResult { + match v { + #[cfg(feature = "redis-unsafe")] + redis::Value::Data(bytes) => Ok(unsafe { Self::from_vec_u8_unchecked(bytes) }), + #[cfg(not(feature = "redis-unsafe"))] + redis::Value::Data(bytes) => Self::from_vec_u8(bytes) + .map_err(|_| (redis::ErrorKind::TypeError, "Invalid UTF8").into()), + redis::Value::Nil => Ok(Self::empty()), + redis::Value::Int(v) => Ok(Self::new(itoa::Buffer::new().format(v))), + redis::Value::Status(s) => Ok(Self::from_string(s)), + redis::Value::Okay => Ok(Self::from_static_str("OK")), + _ => Err(redis::RedisError::from(( + redis::ErrorKind::TypeError, + "Invalid response type", + ))), } } }