#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ExpireCondition {
#[default]
None,
NX,
XX,
GT,
LT,
}
impl ExpireCondition {
#[inline(always)]
pub const fn should_update(self, current_exp: u64, new_exp: u64) -> bool {
match self {
Self::None => true,
Self::NX => current_exp == 0,
Self::XX => current_exp > 0,
Self::GT => current_exp > 0 && new_exp > current_exp,
Self::LT => current_exp == 0 || new_exp < current_exp,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct SortArgs {
pub by: Option<Vec<u8>>,
pub offset: usize,
pub count: Option<usize>,
pub get: Vec<Vec<u8>>,
pub desc: bool,
pub alpha: bool,
pub store: Option<Vec<u8>>,
pub dont_sort: bool,
}
impl SortArgs {
#[inline]
pub fn new() -> Self {
Self::default()
}
#[inline]
pub fn by(mut self, pattern: impl Into<Vec<u8>>) -> Self {
self.by = Some(pattern.into());
self
}
#[inline]
pub fn limit(mut self, offset: usize, count: Option<usize>) -> Self {
self.offset = offset;
self.count = count;
self
}
#[inline]
pub fn get(mut self, pattern: impl Into<Vec<u8>>) -> Self {
self.get.push(pattern.into());
self
}
#[inline]
pub fn desc(mut self) -> Self {
self.desc = true;
self
}
#[inline]
pub fn asc(mut self) -> Self {
self.desc = false;
self
}
#[inline]
pub fn alpha(mut self) -> Self {
self.alpha = true;
self
}
#[inline]
pub fn store(mut self, store_key: impl Into<Vec<u8>>) -> Self {
self.store = Some(store_key.into());
self
}
#[inline]
pub fn dont_sort(mut self) -> Self {
self.dont_sort = true;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct KeyNumStats {
pub n_key: usize,
pub n_expires: usize,
pub n_expired: usize,
pub avg_ttl: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct DBScanInfo {
pub stats: KeyNumStats,
pub last_scan_time_secs: u64,
}