#![forbid(unsafe_code)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(all(not(feature = "std"), not(feature = "external-clock")))]
compile_error!(
"kevy-store without `std` needs the `external-clock` feature: the TTL \
clock must be host-fed when std::time is unavailable"
);
extern crate alloc;
#[cfg(not(feature = "std"))]
pub(crate) mod nostd_prelude {
pub(crate) use alloc::boxed::Box;
pub(crate) use alloc::format;
pub(crate) use alloc::string::{String, ToString};
pub(crate) use alloc::vec::Vec;
}
#[cfg(not(feature = "std"))]
use nostd_prelude::*;
#[cfg(feature = "std")]
pub(crate) type SideMap<K, V> = std::collections::HashMap<K, V>;
#[cfg(not(feature = "std"))]
pub(crate) type SideMap<K, V> = kevy_map::KevyMap<K, V>;
mod accounting;
#[cfg(feature = "std")]
mod bio_drop;
#[cfg(not(feature = "std"))]
impl Store {
#[inline]
pub(crate) fn maybe_offload_drop(&mut self, old: Value) {
drop(old);
}
}
mod bitmap;
mod clock;
mod entry;
mod error;
pub use error::{KevyError, KevyResult};
pub mod evict;
pub mod expire;
pub use expire::ExpireStats;
pub(crate) use entry::Entry;
mod hash;
mod hash_ttl;
pub use hash_ttl::{HExpireCode, HExpireCond};
mod keyspace;
mod keyspace_load;
mod list;
mod notify;
mod rng;
mod scan;
pub use notify::KeyspaceEvent;
mod list_ops;
mod set;
mod small_set;
pub use small_set::{SmallSetData, SmallSetIter};
mod small_hash;
pub use small_hash::{SmallHashData, SmallHashIter};
mod small_list;
pub use small_list::{SmallListData, SmallListIter};
mod small_zset;
pub use small_zset::{SmallZSetData, SmallZSetIter};
mod snapshot;
pub use snapshot::SnapshotView;
mod stream;
mod string;
mod string_rmw;
mod string_set;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
mod segrows;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
mod segwindow;
mod tier;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
mod tier_codec;
mod tier_demote;
mod tier_serve;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub use segrows::SealedRows;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub use segwindow::apply_segmented;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub use tier::TierStats;
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub use tier_serve::{ColdBatchReader, ColdRead, PeekRow, SyncColdRead};
mod types;
pub use types::{EvictionPolicy, RenameOutcome, StoreError};
mod util;
mod value;
mod value_cold;
mod zset;
mod zset_algebra;
mod zset_range;
pub use zset_algebra::{ZAggregate, zdiff, zinter, zintercard, zunion};
mod zset_flags;
pub use zset_flags::{ZaddFlags, ZaddReport};
pub use stream::{
AutoclaimResult, ConsumerGroup, ConsumerState, EntryBatch, GroupCreateMode,
LoadedGroup, LoadedPelEntry, LoadedStreamEntry, PelEntry, PendingExtended,
PendingExtendedRow, PendingSummary, ReadGroupId, StreamData, StreamId, StreamIdError,
XAddIdSpec, XClaimOpts, now_unix_ms, parse_explicit_id, parse_range_end,
parse_range_start, parse_xadd_id,
};
pub use string::{GetReply, GetShared};
pub use util::glob_match;
pub use value::*;
pub(crate) use clock::{deadline_at, now_ns, pack_deadline, remaining_ms};
use kevy_map::KevyMap;
#[cfg(any(feature = "external-clock", all(target_arch = "wasm32", target_os = "unknown")))]
pub use clock::set_clock_ns;
#[cfg(any(feature = "external-clock", all(target_arch = "wasm32", target_os = "unknown")))]
pub use clock::set_wall_clock_ms;
#[derive(Default)]
pub struct Store {
pub(crate) map: KevyMap<SmallBytes, Entry>,
pub(crate) rng: rng::Rng,
pub(crate) hfttl: SideMap<SmallBytes, KevyMap<SmallBytes, u64>>,
pub(crate) cached_ns: u64,
pub(crate) cached_clock: bool,
pub(crate) used_memory: u64,
pub(crate) maxmemory: u64,
pub(crate) eviction_policy: EvictionPolicy,
pub(crate) evictions_total: u64,
pub(crate) clock_counter: u64,
pub(crate) used_memory_peak: u64,
pub(crate) expired_keys_total: u64,
pub(crate) notify_capture: u8,
pub(crate) notify_events: Vec<(notify::KeyspaceEvent, Vec<u8>)>,
pub(crate) expired_keys: Vec<Vec<u8>>,
pub(crate) expires: u64,
pub(crate) watch_versions: SideMap<Vec<u8>, u64>,
#[cfg(feature = "std")]
pub(crate) bio_drop_sender: Option<value::BioDropSender>,
#[cfg(feature = "std")]
pub(crate) pending_drops: Vec<Value>,
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub(crate) tier: Option<tier::TierState>,
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub(crate) segrows: Option<segrows::SegRows>,
#[cfg_attr(any(not(feature = "std"), target_arch = "wasm32"), allow(dead_code))]
pub(crate) cold_backing: bool,
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub(crate) tier_scratch: Option<Entry>,
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
pub(crate) tier_peek: bool,
}
mod store_admin;
#[cfg(not(all(feature = "std", not(target_arch = "wasm32"))))]
impl Store {
pub fn row_seg_files(&self) -> Vec<(u32, alloc::string::String)> {
Vec::new()
}
pub fn load_row_stub(&mut self, _key: Vec<u8>, _seq: u32, _weight: u32) {
panic!("row-segment snapshot record on a target without the segment backend");
}
}
pub(crate) use util::{apply_delta, key_heap_bytes_for};
#[cfg(test)]
mod tests;
#[cfg(test)]
mod tests_memory;
#[cfg(test)]
mod tests_snapshot;
#[cfg(test)]
mod tests_string_encoding;
#[cfg(all(test, feature = "std", not(target_arch = "wasm32")))]
mod tests_tier;
#[cfg(all(test, feature = "std", not(target_arch = "wasm32")))]
mod tests_tier_peek;