wedb_embed 0.1.2

Embedded database engine providing Redis-like APIs, built on fjall / 嵌入式数据库引擎,提供类似 Redis 的接口,底层基于 fjall 开发
Documentation
pub mod conf;
pub mod r#impl;
pub mod key;
pub mod meta;
pub mod traits;

pub use conf::*;
pub use r#impl::*;
pub use key::{
  member as compose_zset_key, meta as compose_zset_meta_key, prefix as compose_zset_prefix,
  score as compose_zset_score_key, score_prefix as compose_zset_score_prefix,
};
pub use meta::*;
pub use traits::ZSet;

pub type ZSetMemberScore = (Vec<u8>, f64);
pub type ZSetKeyMemberScore = (Vec<u8>, Vec<u8>, f64);
pub type ZScanResult = (u64, Vec<ZSetMemberScore>);

use std::ops::Bound;

use crate::{error::Result, meta::parse_redis_float};

/// 解析范围边界(支持 (+inf, (-inf, [val, (val)
pub fn parse_score_bound(s: &str) -> Result<Bound<f64>> {
  let s = s.trim();
  if s == "+inf" {
    return Ok(Bound::Unbounded);
  }
  if s == "-inf" {
    return Ok(Bound::Unbounded);
  }
  if let Some(rest) = s.strip_prefix('(') {
    let val = parse_redis_float(rest.as_bytes(), "ERR min or max is not a float")?;
    Ok(Bound::Excluded(val))
  } else if let Some(rest) = s.strip_prefix('[') {
    let val = parse_redis_float(rest.as_bytes(), "ERR min or max is not a float")?;
    Ok(Bound::Included(val))
  } else {
    let val = parse_redis_float(s.as_bytes(), "ERR min or max is not a float")?;
    Ok(Bound::Included(val))
  }
}