Skip to content

Commit

Permalink
Add: RedisValueHandler to handle the different value types in a Redis…
Browse files Browse the repository at this point in the history
… Result.

It was added first for handling Nil, e.g. when a key is not found.
  • Loading branch information
jjnicola committed Nov 23, 2022
1 parent e7644b1 commit 6f9d932
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions rust/nvtcache/src/redisconnector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ pub mod redisconnector {
maxdb: u32, // max db index
}

#[derive(Debug, PartialEq)]
pub struct RedisValueHandler {
v: String,
}

impl FromRedisValue for RedisValueHandler {
fn from_redis_value(v: &Value) -> RedisResult<RedisValueHandler> {
match v {
Value::Nil => Ok(RedisValueHandler { v: String::new() }),
_ => {
let new_var: String = from_redis_value(v).unwrap_or("".to_string());
Ok(RedisValueHandler { v: new_var })
}
}
}
}

impl RedisCtx {
/// Connect to the redis server and return a redis context object
pub fn new() -> Result<RedisCtx> {
Expand Down

0 comments on commit 6f9d932

Please sign in to comment.