Skip to main content

redis_value

Macro redis_value 

Source
macro_rules! redis_value {
    ({$($k:tt: $v:tt),* $(,)*}) => { ... };
    ([$($e:tt),* $(,)*]) => { ... };
    (set:[$($e:tt),* $(,)*]) => { ... };
    (simple:$e:tt) => { ... };
    (nil) => { ... };
    (ok) => { ... };
    (okay) => { ... };
    (($context:tt:$e:tt)) => { ... };
    ($e:expr) => { ... };
}
Expand description

Build Values from a JSON-like notation

This macro handles:

  • u8, u16, u32, i8, i16, i32, i64, String, &str and other types that implement IntoRedisValue
  • true, false - map to their corresponding Value::Boolean
  • nil - maps to Value::Nil
  • ok, okay - map to Value::Okay
  • [element1, element2, ..., elementN] - maps to Value::Array
  • {key1: value1, key2: value2, ..., keyN: valueN] - maps to Value::Map
  • set:[element1, element2, ..., elementN] - maps to Value::Set (wrap in () within complex structures)
  • simple:"SomeString" - maps to Value::SimpleString (wrap in () within complex structures)

ยงExample

use redis::Value;
use redis_test::redis_value;

let actual = redis_value!([42, "foo", {true: nil}]);

let expected = Value::Array(vec![
  Value::Int(42),
  Value::BulkString("foo".as_bytes().to_vec()),
  Value::Map(vec![(Value::Boolean(true), Value::Nil)])
]);
assert_eq!(actual, expected)