#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum HExpire {
#[default]
None,
Nx,
Xx,
Gt,
Lt,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum HashFieldSetCondition {
#[default]
None,
Fnx,
Fxx,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TTLAction {
#[default]
Discard,
Keep,
Set,
Persist,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HSet {
Ex(u64),
Px(u64),
ExAt(u64),
PxAt(u64),
KeepTtl,
Fnx,
Fxx,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct HashSetEx {
pub condition: HashFieldSetCondition,
pub ttl_action: TTLAction,
pub expire_at_ms: u64,
}
impl HashSetEx {
#[inline]
pub const fn new(
condition: HashFieldSetCondition,
ttl_action: TTLAction,
expire_at_ms: u64,
) -> Self {
Self {
condition,
ttl_action,
expire_at_ms,
}
}
pub fn from_options(options: impl IntoIterator<Item = HSet>, now_ms: u64) -> Self {
let mut opts = Self::default();
for flag in options {
match flag {
HSet::Ex(sec) => {
opts.ttl_action = TTLAction::Set;
opts.expire_at_ms = now_ms.saturating_add(sec.saturating_mul(1000));
}
HSet::Px(ms) => {
opts.ttl_action = TTLAction::Set;
opts.expire_at_ms = now_ms.saturating_add(ms);
}
HSet::ExAt(sec) => {
opts.ttl_action = TTLAction::Set;
opts.expire_at_ms = sec.saturating_mul(1000);
}
HSet::PxAt(ms) => {
opts.ttl_action = TTLAction::Set;
opts.expire_at_ms = ms;
}
HSet::KeepTtl => {
opts.ttl_action = TTLAction::Keep;
}
HSet::Fnx => {
opts.condition = HashFieldSetCondition::Fnx;
}
HSet::Fxx => {
opts.condition = HashFieldSetCondition::Fxx;
}
}
}
opts
}
pub fn from_flags(flags: &[HSet], now_ms: u64) -> Self {
Self::from_options(flags.iter().copied(), now_ms)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HGetEx {
Ex(u64),
Px(u64),
ExAt(u64),
PxAt(u64),
Persist,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct HashGetEx {
pub ttl_action: TTLAction,
pub expire_at_ms: u64,
}
impl HashGetEx {
#[inline]
pub const fn new(ttl_action: TTLAction, expire_at_ms: u64) -> Self {
Self {
ttl_action,
expire_at_ms,
}
}
#[inline]
pub const fn persist() -> Self {
Self {
ttl_action: TTLAction::Persist,
expire_at_ms: 0,
}
}
pub fn from_options(options: impl IntoIterator<Item = HGetEx>, now_ms: u64) -> Self {
let mut opt_iter = options.into_iter();
if let Some(flag) = opt_iter.next() {
match flag {
HGetEx::Ex(sec) => Self::new(
TTLAction::Set,
now_ms.saturating_add(sec.saturating_mul(1000)),
),
HGetEx::Px(ms) => Self::new(TTLAction::Set, now_ms.saturating_add(ms)),
HGetEx::ExAt(sec) => Self::new(TTLAction::Set, sec.saturating_mul(1000)),
HGetEx::PxAt(ms) => Self::new(TTLAction::Set, ms),
HGetEx::Persist => Self::persist(),
}
} else {
Self::default()
}
}
pub fn from_flag(flag: HGetEx, now_ms: u64) -> Self {
Self::from_options([flag], now_ms)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum HashLengthMode {
#[default]
Accurate = 0,
Approximate = 1,
}
pub use crate::zset::opt::RangeLex;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FieldValue<F = Vec<u8>, V = Vec<u8>> {
pub field: F,
pub value: V,
}
impl<F, V> FieldValue<F, V> {
#[inline]
pub const fn new(field: F, value: V) -> Self {
Self { field, value }
}
}