Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Str(SmallBytes),
    Int(i64),
    ArcBulk(Arc<Box<[u8]>>),
    Hash(Arc<HashData>),
    List(Arc<ListData>),
    Set(Arc<SetData>),
    ZSet(Arc<ZSetData>),
    Stream(Arc<StreamData>),
    SmallSetInline(SmallSetData),
    SmallHashInline(SmallHashData),
    SmallListInline(SmallListData),
    SmallZSetInline(SmallZSetData),
}
Expand description

A stored value. One variant per Redis type.

The collection variants live behind a shared pointer (Arc) so the enum is only as big as Str (24 B) + tag = 32 B, not the 56 B ZSetData — every Entry (incl. the common string case) is then ~48 B instead of ~80 B, so the bucket array is ~40% denser/smaller (fewer cache misses on a large keyspace, less RSS). The extra pointer-chase lands only on collection ops, not the hot string GET path.

Arc (same 8 B as the previous Box) is what makes O(short-pause) persistence possible: crate::Store::collect_snapshot bumps each collection’s refcount instead of serializing it, and a background thread walks the frozen payloads at leisure. Mutations go through std::sync::Arc::make_mut — a single uniqueness check (the steady state, no snapshot in flight) or a copy-on-write deep clone when a snapshot still holds the payload.

Str holds a SmallBytes (24 B, same size as Vec<u8>) so byte strings up to 22 bytes live inline inside the bucket, killing the second cache miss the value pointer-chase used to cost on large-keyspace GETs. Clone is the snapshot-collect primitive: Str copies its bytes (inline = 24 B memcpy; heap = one allocation), collections bump a refcount. See crate::Store::collect_snapshot.

Variants§

§

Str(SmallBytes)

§

Int(i64)

L2 (2026-06-21, lessons from valkey OBJ_ENCODING_INT): when a SET stores a clean canonical i64 ASCII string (parses round-trip), we keep the integer as i64 rather than as 22 B of inline bytes. Wins on INCR (in-place += delta, no parse / no format / no SmallBytes wrap) and on memory (8 B vs 24 B). GET formats it via a per-Store scratch buffer.

§

ArcBulk(Arc<Box<[u8]>>)

L1 (2026-06-21) / v1.29 Option A (2026-06-29): values larger than BULK_THRESHOLD bytes get stored behind an Arc<Box<[u8]>> instead of a heap-backed SmallBytes. The Arc lets the io_uring reactor’s reply path borrow the bytes across the SQE→CQE window safely (Arc clone keeps them alive even if the keyspace mutates) — the prerequisite for the writev zero-copy bulk reply path, which skips the per-GET memcpy from value storage into the per-conn output buffer.

Why Arc<Box<[u8]>> and not Arc<[u8]>: Arc<[u8]> is a DST-backed ArcInner<[u8]> = { strong, weak, [u8; N] } whose data slot sits past the refcount words. Arc::from(Vec<u8>) allocates a fresh ArcInner and copy_from_slices the bytes — a hard mandatory 64 KiB memcpy on every big SET. With Arc<Box<[u8]>>, the Box<[u8]> wrapper occupies the Arc’s data slot (16 B), pointing AT an unchanged heap buffer; so Arc::new(vec.into_boxed_slice()) is truly zero-copy (the boxed slice’s allocation stays put — only the 32-byte ArcInner is freshly malloced). Per-GET cost: one extra pointer dereference (&**arc to get &[u8]), measured to be negligible vs the per-SET memcpy savings. See bench/PERF-FINDING-2026-06-29-arc-from-box-memcpys.md for the empirical perf-record evidence of the original Arc<[u8]> mandatory copy.

Small values stay on Str(SmallBytes) because the inline cache-line storage beats an Arc indirection for the common case.

§

Hash(Arc<HashData>)

§

List(Arc<ListData>)

§

Set(Arc<SetData>)

§

ZSet(Arc<ZSetData>)

§

Stream(Arc<StreamData>)

§

SmallSetInline(SmallSetData)

v1.25 A.7 O5 (valkey-orthodox encoding switch): tiny sets (1-N short members) live inline in 24 bytes instead of behind Arc<SetData> — matches valkey’s OBJ_ENCODING_LISTPACK for sets, which is what redis-benchmark -t sadd default -r 0 (cardinality stays at 1 forever, single 20-byte literal member) measures. On overflow (crate::small_set::SmallSetData::try_add returns NoRoom) the set is promoted to Value::Set(Arc<SetData>) — the Swiss-table path that wins for larger cardinalities.

§

SmallHashInline(SmallHashData)

v1.25 A.8 (extension of A.7 to hashes): tiny hashes (1-2 short field-value pairs) live inline in 24 bytes; promoted to Value::Hash(Arc<HashData>) on overflow. Mirrors valkey’s OBJ_ENCODING_LISTPACK for hashes.

§

SmallListInline(SmallListData)

v1.25 A.8: tiny lists inline encoding; promoted to Value::List(Arc<ListData>) on overflow.

§

SmallZSetInline(SmallZSetData)

v1.25 A.8: tiny sorted sets inline encoding; promoted to Value::ZSet(Arc<ZSetData>) on overflow.

Implementations§

Source§

impl Value

Source

pub fn type_name(&self) -> &'static str

The Redis type name (TYPE command).

Source

pub fn weight(&self) -> u64

Approximate heap bytes the value owns. Excludes the inline Entry / bucket slot — that’s a separate per-entry constant accounted by the store. Walks collections, so prefer the cached Entry::weight for hot-path accounting and only call this when bootstrapping or after a load-from-snapshot.

Source

pub fn is_heap_heavy(&self) -> bool

Whether this value’s Drop is heavy enough to deserve being shipped to the bio thread instead of freed inline. Fast: every variant decides off a sub-field cheap to inspect (no recursive walk), so it’s safe to call on every overwrite-SET on the hot path. The threshold is intentionally conservative — small Arcs

  • every short string stay on inline-drop where jemalloc small- class is sub-µs and a cross-thread hand-off would lose.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.