pub struct ConcurrentKeyspace { /* private fields */ }Expand description
A concurrent keyspace backed by DashMap.
Provides thread-safe access to key-value data without channel overhead. All operations are lock-free for non-conflicting keys.
Implementations§
Source§impl ConcurrentKeyspace
impl ConcurrentKeyspace
Sourcepub fn new(max_memory: Option<usize>, eviction_policy: EvictionPolicy) -> Self
pub fn new(max_memory: Option<usize>, eviction_policy: EvictionPolicy) -> Self
Creates a new concurrent keyspace with optional memory limit.
Sourcepub fn get(&self, key: &str) -> Option<Bytes>
pub fn get(&self, key: &str) -> Option<Bytes>
Gets a value by key, returning None if not found or expired.
Sourcepub fn set(&self, key: String, value: Bytes, ttl: Option<Duration>) -> bool
pub fn set(&self, key: String, value: Bytes, ttl: Option<Duration>) -> bool
Sets a key-value pair with optional TTL.
Sourcepub fn random_key(&self) -> Option<String>
pub fn random_key(&self) -> Option<String>
Returns a random non-expired key, or None if the keyspace is empty.
Sourcepub fn incr(&self, key: &str) -> Result<i64, ConcurrentOpError>
pub fn incr(&self, key: &str) -> Result<i64, ConcurrentOpError>
Increments the integer value of a key by 1. If the key doesn’t exist, it’s initialized to 0 before incrementing.
Sourcepub fn decr(&self, key: &str) -> Result<i64, ConcurrentOpError>
pub fn decr(&self, key: &str) -> Result<i64, ConcurrentOpError>
Decrements the integer value of a key by 1. If the key doesn’t exist, it’s initialized to 0 before decrementing.
Sourcepub fn incr_by(&self, key: &str, delta: i64) -> Result<i64, ConcurrentOpError>
pub fn incr_by(&self, key: &str, delta: i64) -> Result<i64, ConcurrentOpError>
Adds delta to the integer value of a key, creating it if missing.
Preserves existing TTL when updating.
Sourcepub fn incr_by_float(
&self,
key: &str,
delta: f64,
) -> Result<f64, ConcurrentFloatError>
pub fn incr_by_float( &self, key: &str, delta: f64, ) -> Result<f64, ConcurrentFloatError>
Adds delta to the float value of a key, creating it if missing.
Preserves existing TTL when updating.
Sourcepub fn append(&self, key: &str, suffix: &[u8]) -> usize
pub fn append(&self, key: &str, suffix: &[u8]) -> usize
Appends a value to an existing string key, or creates a new key. Returns the new string length.
Sourcepub fn strlen(&self, key: &str) -> usize
pub fn strlen(&self, key: &str) -> usize
Returns the length of the string value stored at key. Returns 0 if the key doesn’t exist.
Sourcepub fn persist(&self, key: &str) -> bool
pub fn persist(&self, key: &str) -> bool
Removes the expiration from a key. Returns true if the timeout was successfully removed.
Sourcepub fn pexpire(&self, key: &str, millis: u64) -> bool
pub fn pexpire(&self, key: &str, millis: u64) -> bool
Sets expiration in milliseconds on an existing key.
Sourcepub fn scan_keys(
&self,
cursor: u64,
count: usize,
pattern: Option<&str>,
) -> (u64, Vec<String>)
pub fn scan_keys( &self, cursor: u64, count: usize, pattern: Option<&str>, ) -> (u64, Vec<String>)
Iterates keys using a cursor. Returns (next_cursor, keys). A next_cursor of 0 means the iteration is complete.
Sourcepub fn rename(&self, key: &str, newkey: &str) -> Result<(), &'static str>
pub fn rename(&self, key: &str, newkey: &str) -> Result<(), &'static str>
Renames a key. Returns true if the source key existed.
Sourcepub fn memory_used(&self) -> usize
pub fn memory_used(&self) -> usize
Returns memory usage in bytes.