pub struct KvAtomicOps<'a> { /* private fields */ }Expand description
Atomic KV operations interface — the seam that transports and drivers depend on.
All three verbs delegate to the runtime’s existing create_kv / get_kv /
delete_kv plumbing; this struct adds the auto-create and upsert logic.
Implementations§
Source§impl<'a> KvAtomicOps<'a>
impl<'a> KvAtomicOps<'a>
pub fn new(runtime: &'a RedDBRuntime) -> Self
Sourcepub fn set(
&self,
model: CollectionModel,
collection: &str,
key: &str,
value: Value,
ttl_ms: Option<u64>,
if_not_exists: bool,
) -> RedDBResult<(bool, EntityId)>
pub fn set( &self, model: CollectionModel, collection: &str, key: &str, value: Value, ttl_ms: Option<u64>, if_not_exists: bool, ) -> RedDBResult<(bool, EntityId)>
Insert or update a KV entry. Auto-creates the collection when needed.
Insert or update a KV entry. Returns (created: bool, id: EntityId).
Sourcepub fn get(
&self,
model: CollectionModel,
collection: &str,
key: &str,
) -> RedDBResult<Option<Value>>
pub fn get( &self, model: CollectionModel, collection: &str, key: &str, ) -> RedDBResult<Option<Value>>
Retrieve a KV value by key. Returns None when not found.
Sourcepub fn delete(
&self,
model: CollectionModel,
collection: &str,
key: &str,
) -> RedDBResult<bool>
pub fn delete( &self, model: CollectionModel, collection: &str, key: &str, ) -> RedDBResult<bool>
Delete a KV entry. Returns true if the key existed.
Sourcepub fn incr(
&self,
model: CollectionModel,
collection: &str,
key: &str,
by: i64,
ttl_ms: Option<u64>,
) -> RedDBResult<i64>
pub fn incr( &self, model: CollectionModel, collection: &str, key: &str, by: i64, ttl_ms: Option<u64>, ) -> RedDBResult<i64>
Atomically increment (or decrement) a counter key. Returns the new value.
- Missing key initialises at
by(Redis-compat). - Non-integer value returns an error before any mutation.
Sourcepub fn cas(
&self,
model: CollectionModel,
collection: &str,
key: &str,
expected: Option<&Value>,
new_value: Value,
ttl_ms: Option<u64>,
) -> RedDBResult<(bool, Option<Value>)>
pub fn cas( &self, model: CollectionModel, collection: &str, key: &str, expected: Option<&Value>, new_value: Value, ttl_ms: Option<u64>, ) -> RedDBResult<(bool, Option<Value>)>
Compare-and-set: atomically swap key from expected to new_value.
Returns (ok, current):
ok = true→ swap applied;currentis the value before the swap.ok = false→ swap skipped;currentholds the actual current value.
expected = None means the caller expects the key to be absent (create-if-absent).
Auto Trait Implementations§
impl<'a> Freeze for KvAtomicOps<'a>
impl<'a> !RefUnwindSafe for KvAtomicOps<'a>
impl<'a> Send for KvAtomicOps<'a>
impl<'a> Sync for KvAtomicOps<'a>
impl<'a> Unpin for KvAtomicOps<'a>
impl<'a> UnsafeUnpin for KvAtomicOps<'a>
impl<'a> !UnwindSafe for KvAtomicOps<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request