Skip to main content

ConcurrentKeyspace

Struct ConcurrentKeyspace 

Source
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

Source

pub fn new(max_memory: Option<usize>, eviction_policy: EvictionPolicy) -> Self

Creates a new concurrent keyspace with optional memory limit.

Source

pub fn get(&self, key: &str) -> Option<Bytes>

Gets a value by key, returning None if not found or expired.

Source

pub fn set(&self, key: String, value: Bytes, ttl: Option<Duration>) -> bool

Sets a key-value pair with optional TTL.

Source

pub fn del(&self, key: &str) -> bool

Deletes a key, returning true if it existed.

Source

pub fn exists(&self, key: &str) -> bool

Checks if a key exists (and is not expired).

Source

pub fn random_key(&self) -> Option<String>

Returns a random non-expired key, or None if the keyspace is empty.

Source

pub fn ttl(&self, key: &str) -> TtlResult

Returns the TTL of a key.

Source

pub fn expire(&self, key: &str, seconds: u64) -> bool

Sets expiration on a key.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn persist(&self, key: &str) -> bool

Removes the expiration from a key. Returns true if the timeout was successfully removed.

Source

pub fn pexpire(&self, key: &str, millis: u64) -> bool

Sets expiration in milliseconds on an existing key.

Source

pub fn pttl(&self, key: &str) -> TtlResult

Returns the remaining TTL in milliseconds.

Source

pub fn keys(&self, pattern: &str) -> Vec<String>

Returns all keys matching a glob pattern.

Source

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.

Source

pub fn rename(&self, key: &str, newkey: &str) -> Result<(), &'static str>

Renames a key. Returns true if the source key existed.

Source

pub fn len(&self) -> usize

Returns the number of keys.

Source

pub fn is_empty(&self) -> bool

Returns true if the keyspace is empty.

Source

pub fn memory_used(&self) -> usize

Returns memory usage in bytes.

Source

pub fn ops_count(&self) -> u64

Returns the operation count.

Source

pub fn clear(&self)

Clears all keys.

Trait Implementations§

Source§

impl Debug for ConcurrentKeyspace

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConcurrentKeyspace

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> OptionalSend for T
where T: Send + ?Sized,

Source§

impl<T> OptionalSync for T
where T: Sync + ?Sized,