Function from_redis_value

Source
pub fn from_redis_value<T: FromRedisValue>(value: &RedisValue) -> RedisResult<T>
Expand description

Convert RedisValue into T value.

ยงExample

use redis_asio::{RedisValue, from_redis_value};

let redis_value = RedisValue::BulkString(b"some data".to_vec());
let origin = "some data".to_string();
let result : String = from_redis_value::<String>(&redis_value).unwrap();
assert_eq!(origin, result);
Examples found in repository?
examples/stream_consumer.rs (line 55)
42    fn from_redis_stream_entry(key_values: &HashMap<String, RedisValue>) -> RedisResult<Self> {
43        if key_values.len() != 2 {
44            return Err(RedisError::new(RedisErrorKind::ParseError,
45                                       "Invalid packet".to_string()));
46        }
47
48        let get_value =
49            |key: &str| match key_values.get(key) {
50                Some(x) => Ok(x),
51                _ => Err(RedisError::new(RedisErrorKind::ParseError,
52                                         "Invalid packet".to_string()))
53            };
54
55        let packet_type: String = from_redis_value(get_value("type")?)?;
56        match packet_type.as_str() {
57            "Message" => {
58                let data: Message = from_redis_value(get_value("data")?)?;
59                Ok(data)
60            }
61            _ => Err(RedisError::new(RedisErrorKind::ParseError,
62                                     "Unknown message type".to_string()))
63        }
64    }