Skip to content

Commit

Permalink
Merge pull request #179 from Enraged-Dun-Cookie-Development-Team/fix/…
Browse files Browse the repository at this point in the history
…coolieid-serialize

🐛 修复CookieID读自Redis解析方式错误
  • Loading branch information
Goodjooy authored May 8, 2024
2 parents 3ed19b1 + 0cefb57 commit 47a3fb3
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions global/redis_global/src/cookie_id/redis.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::array::TryFromSliceError;

use bson::oid::ObjectId;
use redis::{FromRedisValue, RedisError, RedisResult, RedisWrite, Value};

impl redis::ToRedisArgs for super::CookieId {
Expand All @@ -11,15 +14,25 @@ impl redis::ToRedisArgs for super::CookieId {

impl FromRedisValue for super::CookieId {
fn from_redis_value(v: &Value) -> RedisResult<Self> {
let inner = String::from_redis_value(v)?.parse().map_err(
|err: bson::oid::Error| {
RedisError::from((
match v {
Value::Data(data) => {
let buffer: [u8; 12] = data.as_slice().try_into().map_err(
|err: TryFromSliceError| {
RedisError::from((
redis::ErrorKind::TypeError,
"Length Not Enough",
err.to_string(),
))
},
)?;
Ok(Self(ObjectId::from(buffer)))
}
_ => {
Err(RedisError::from((
redis::ErrorKind::TypeError,
"Bad ObjectId Format",
err.to_string(),
))
},
)?;
Ok(Self(inner))
"Unsupported CookieId Type",
)))
}
}
}
}

0 comments on commit 47a3fb3

Please sign in to comment.