Type Alias fred::types::Resp2TimeSeriesValues

source ·
pub type Resp2TimeSeriesValues<K, Lk, Lv> = Vec<(K, Vec<(Lk, Lv)>, Vec<(i64, f64)>)>;
Available on crate feature i-time-series only.
Expand description

Shorthand for the result of commands such as MGET, MRANGE, etc.

  • K - The key type, usually a RedisKey, Str, or String.
  • Lk - The label key type, usually a Str or String.
  • Lv - The label value type, often some kind of string type.

The fastest/cheapest option is usually TimeseriesValues<RedisKey, Str, Str>.

async fn example(client: &RedisClient) -> Result<(), RedisError> {
  assert_eq!(client.protocol_version(), RespVersion::RESP2);

  client
    .ts_add("foo", "*", 1.1, None, None, None, None, ("a", "b"))
    .await?;
  sleep(Duration::from_millis(5)).await;
  client
    .ts_add("foo", "*", 2.2, None, None, None, None, ("a", "b"))
    .await?;
  sleep(Duration::from_millis(5)).await;
  client
    .ts_add("bar", "*", 3.3, None, None, None, None, ("a", "b"))
    .await?;
  sleep(Duration::from_millis(5)).await;
  client
    .ts_add("bar", "*", 4.4, None, None, None, None, ("a", "b"))
    .await?;

  let ranges: Resp2TimeSeriesValues<RedisKey, Str, Str> = client
    .ts_mrange(
      "-",
      "+",
      true,
      [],
      None,
      Some(GetLabels::WithLabels),
      None,
      None,
      ["a=b"],
      None,
    )
    .await?;

  for (key, labels, values) in ranges.into_iter() {
    println!("{} [{:?}] {:?}", key.as_str_lossy(), labels, values);
  }
  // bar [[("a", "b")]] [(1705355605510, 3.3), (1705355605517, 4.4)]
  // foo [[("a", "b")]] [(1705355605498, 1.1), (1705355605504, 2.2)]
  Ok(())
}

See Resp3TimeSeriesValues for the RESP3 equivalent.

Aliased Type§

struct Resp2TimeSeriesValues<K, Lk, Lv> { /* private fields */ }