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::{
  ERR_HASH_FIELD_EXPIRATION_LEGACY_ENCODING, ERR_HASH_VALUE_NOT_FLOAT, ERR_HASH_VALUE_NOT_INTEGER,
  ERR_INCREMENT_NAN_OR_INFINITY, ERR_INCREMENT_OVERFLOW, ERR_WRONG_TYPE, FieldValue,
  HASH_EXPIRE_COND_FAILED, HASH_EXPIRE_DELETED, HASH_EXPIRE_SET_OK, HASH_FIELD_NOT_FOUND,
  HASH_FIELD_PERSISTENT, HExpire, HGetEx, HSetEx, HashFetchType, HashFieldExpireCondition,
  HashFieldSetCondition, HashGetExOptions, HashLengthMode, HashSetExOptions, RangeLexSpec,
  TTLAction,
};
pub use r#impl::*;
pub use meta::{
  FIELD_EXPIRE_PREFIX_LEN, HashFieldState, HashFieldStateKind, HashItemKeyComposer, HashMeta,
  HashSubkeyEncodingMode, compose_hash_key, compose_hash_meta_key, compose_hash_prefix,
  compose_hash_prefix_stack, decode_field_state, decode_hash_value, encode_hash_value,
  hexpire_condition_passes, is_field_expired, is_immediate_expire,
};
pub use traits::Hash;

pub type HashFieldPair = (Vec<u8>, Vec<u8>);
pub type HashRandField = (Vec<u8>, Option<Vec<u8>>);
pub type HashScanResult = (usize, Vec<HashFieldPair>);

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

/// 向上取整除以 1000(对标 Kvrocks CeilDiv1000)
#[inline(always)]
pub(crate) const fn ceil_div_1000(val: u64) -> u64 {
  val.div_ceil(1000)
}

/// 解析 Redis 整数(严格校验空白符与合法性)
#[inline]
pub(crate) fn parse_hash_integer(v: &[u8]) -> Result<i64> {
  parse_redis_integer(v, ERR_HASH_VALUE_NOT_INTEGER)
}

/// 解析 Redis 浮点数(严格校验空白符与浮点合法性)
#[inline]
pub(crate) fn parse_hash_float(v: &[u8]) -> Result<f64> {
  parse_redis_float(v, ERR_HASH_VALUE_NOT_FLOAT)
}

/// 缓存的字段状态与原始物理切片
#[derive(Clone)]
pub(crate) struct CachedFieldState {
  pub kind: HashFieldStateKind,
  pub expire: u64,
  pub raw: Option<fjall::Slice>,
}