From 62ade0a4c219a8c46ea75a6bfb5e90e2b6db0d98 Mon Sep 17 00:00:00 2001 From: Pure White Date: Thu, 5 Dec 2024 12:17:06 +0800 Subject: [PATCH] chore: bump version to 0.2.25 --- Cargo.lock | 20 +++++++++++++++-- Cargo.toml | 5 +++-- src/redis.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7c8d88..9e47760 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,13 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "faststr" -version = "0.2.24" +version = "0.2.25" dependencies = [ "bytes", "criterion", "itoa", - "redis", + "redis 0.26.1", + "redis 0.27.6", "rkyv", "ryu", "serde", @@ -636,6 +637,21 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "redis" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e902a69d09078829137b4a5d9d082e0490393537badd7c91a3d69d14639e115f" +dependencies = [ + "arc-swap", + "combine", + "itoa", + "num-bigint", + "percent-encoding", + "ryu", + "url", +] + [[package]] name = "redis" version = "0.27.6" diff --git a/Cargo.toml b/Cargo.toml index 37cdf10..1d493d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "faststr" -version = "0.2.24" +version = "0.2.25" authors = ["Volo Team "] edition = "2021" description = "Faststr is a string library that reduces the cost of clone." @@ -18,6 +18,7 @@ simdutf8 = { version = "0.1", default-features = false, features = [ "aarch64_neon", ] } redis = { version = "0.27", optional = true, default-features = false } +redis-0-26 = { version = "0.26", optional = true, default-features = false, package = "redis" } itoa = { version = "1", optional = true } ryu = { version = "1", optional = true } rkyv = { version = "0.8", optional = true, default-features = false } @@ -27,7 +28,7 @@ default = ["std"] std = ["bytes/std", "simdutf8/std", "serde?/std", "rkyv?/std"] serde = ["serde/alloc"] serde-unsafe = ["serde"] -redis = ["std", "dep:redis", "itoa", "ryu"] +redis = ["std", "dep:redis", "itoa", "ryu", "dep:redis-0-26"] redis-unsafe = ["redis"] rkyv = ["rkyv/alloc"] diff --git a/src/redis.rs b/src/redis.rs index 6905fb0..c673f50 100644 --- a/src/redis.rs +++ b/src/redis.rs @@ -55,3 +55,66 @@ impl redis::FromRedisValue for crate::FastStr { } } } + +mod compat_0_26 { + use redis_0_26 as redis; + impl redis::ToRedisArgs for crate::FastStr { + fn write_redis_args(&self, out: &mut W) + where + W: ?Sized + redis::RedisWrite, + { + out.write_arg(self.as_bytes()) + } + } + + impl redis::FromRedisValue for crate::FastStr { + fn from_redis_value(v: &redis::Value) -> redis::RedisResult { + match v { + redis::Value::Nil => Ok(Self::empty()), + redis::Value::Int(v) => Ok(Self::new(itoa::Buffer::new().format(*v))), + redis::Value::Okay => Ok(Self::from_static_str("OK")), + #[cfg(feature = "redis-unsafe")] + redis::Value::BulkString(v) => { + Ok(unsafe { Self::new(std::str::from_utf8_unchecked(v)) }) + } + #[cfg(not(feature = "redis-unsafe"))] + redis::Value::BulkString(v) => Ok(Self::new(std::str::from_utf8(v)?)), + redis::Value::SimpleString(v) => Ok(Self::new(v)), + redis::Value::Double(v) => Ok(Self::new(ryu::Buffer::new().format(*v))), + redis::Value::Boolean(v) => { + Ok(Self::from_static_str(if *v { "true" } else { "false" })) + } + redis::Value::BigNumber(v) => Ok(Self::from_string(v.to_string())), + e => Err(redis::RedisError::from(( + redis::ErrorKind::TypeError, + "Invalid response type", + format!("{:?}", e), + ))), + } + } + + fn from_owned_redis_value(v: redis::Value) -> redis::RedisResult { + match v { + #[cfg(feature = "redis-unsafe")] + redis::Value::BulkString(v) => Ok(unsafe { Self::from_vec_u8_unchecked(v) }), + #[cfg(not(feature = "redis-unsafe"))] + redis::Value::BulkString(v) => Self::from_vec_u8(v) + .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::Okay => Ok(Self::from_static_str("OK")), + redis::Value::SimpleString(v) => Ok(Self::from_string(v)), + redis::Value::Double(v) => Ok(Self::new(ryu::Buffer::new().format(v))), + redis::Value::Boolean(v) => { + Ok(Self::from_static_str(if v { "true" } else { "false" })) + } + redis::Value::BigNumber(v) => Ok(Self::from_string(v.to_string())), + e => Err(redis::RedisError::from(( + redis::ErrorKind::TypeError, + "Invalid response type", + format!("{:?}", e), + ))), + } + } + } +}