Skip to main content

MemoryTracker

Struct MemoryTracker 

Source
pub struct MemoryTracker { /* private fields */ }
Expand description

Tracks memory usage for a single keyspace.

All updates are explicit — callers must call add / remove on every mutation. This avoids any hidden scanning cost.

Implementations§

Source§

impl MemoryTracker

Source

pub fn new() -> Self

Creates a tracker with zero usage.

Source

pub fn reset(&mut self)

Resets tracking to zero. Used by FLUSHDB.

Source

pub fn used_bytes(&self) -> usize

Returns the current estimated memory usage in bytes.

Source

pub fn key_count(&self) -> usize

Returns the number of tracked keys.

Source

pub fn add(&mut self, key: &str, value: &Value)

Records the addition of a new entry.

Source

pub fn remove(&mut self, key: &str, value: &Value)

Records the removal of an entry.

Source

pub fn replace(&mut self, key: &str, old_value: &Value, new_value: &Value)

Adjusts tracking when a key’s value is overwritten.

Removes the old value’s contribution and adds the new one. Key count stays the same.

Source

pub fn adjust(&mut self, old_entry_size: usize, new_entry_size: usize)

Adjusts used bytes for an in-place mutation (e.g. list push/pop) without changing the key count.

old_entry_size and new_entry_size are the full entry sizes (as returned by entry_size) before and after the mutation.

Source

pub fn grow_by(&mut self, delta: usize)

Increases used bytes by delta without scanning the entry.

Use this when the caller already knows the exact number of bytes being added (e.g. list push where element sizes are precomputed). Does not change the key count.

Source

pub fn shrink_by(&mut self, delta: usize)

Decreases used bytes by delta without scanning the entry.

Use this when the caller already knows the exact number of bytes being removed (e.g. list pop where the popped element length is known). Does not change the key count.

Source

pub fn remove_with_size(&mut self, size: usize)

Removes an entry with an explicit size, useful when the value has already been mutated and the original size was captured beforehand.

Trait Implementations§

Source§

impl Debug for MemoryTracker

Source§

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

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

impl Default for MemoryTracker

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,