Skip to content

Commit

Permalink
🐛 修复CookieID读自Redis解析方式错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodjooy committed May 8, 2024
1 parent 3ed19b1 commit 0cefb57
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 0cefb57

Please sign in to comment.