Skip to content

Commit

Permalink
feat: update redis to 0.25 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWhiteWu authored Mar 11, 2024
1 parent b5d5b78 commit 0e40fea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "faststr"
version = "0.2.17"
version = "0.2.18"
authors = ["Volo Team <[email protected]>"]
edition = "2021"
description = "Faststr is a string library that reduces the cost of clone."
Expand All @@ -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]
Expand Down
28 changes: 15 additions & 13 deletions src/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@ impl redis::FromRedisValue for crate::FastStr {
}
}

fn from_byte_vec(vec: &[u8]) -> Option<Vec<Self>> {
#[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<Self> {
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",
))),
}
}
}

0 comments on commit 0e40fea

Please sign in to comment.