diff --git a/global/redis_global/src/cookie_id/redis.rs b/global/redis_global/src/cookie_id/redis.rs index c25f3de7..74fd7774 100644 --- a/global/redis_global/src/cookie_id/redis.rs +++ b/global/redis_global/src/cookie_id/redis.rs @@ -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 { @@ -11,15 +14,25 @@ impl redis::ToRedisArgs for super::CookieId { impl FromRedisValue for super::CookieId { fn from_redis_value(v: &Value) -> RedisResult { - 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", + ))) + } + } } }