Struct ValkeyKeyWritable

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

ValkeyKeyWritable is an abstraction over a Valkey key that allows read and write operations.

Implementations§

Source§

impl ValkeyKeyWritable

Source

pub fn open(ctx: *mut RedisModuleCtx, key: &ValkeyString) -> Self

Source

pub fn is_empty(&self) -> bool

Returns true if the key is of type KeyType::Empty.

§Note

An empty key can be reliably detected by looking for a null as the key is opened ValkeyKeyWritable::open in read mode, but when asking for a write, Valkey returns a non-null pointer to allow to write to even an empty key. In that case, the key’s value should be checked manually instead:

use valkey_module::key::ValkeyKeyWritable;
use valkey_module::ValkeyError;

fn is_empty_old(key: &ValkeyKeyWritable) -> Result<bool, ValkeyError> {
    let mut s = key.as_string_dma()?;
    let is_empty = s.write(b"new value")?.is_empty();
    Ok(is_empty)
}
Source

pub fn as_string_dma(&self) -> Result<StringDMA<'_>, ValkeyError>

Source

pub fn hash_set(&self, field: &str, value: ValkeyString) -> Status

Source

pub fn hash_del(&self, field: &str) -> Status

Source

pub fn hash_get(&self, field: &str) -> Result<Option<ValkeyString>, ValkeyError>

Source

pub fn hash_get_multi<'a, A, B>( &self, fields: &'a [A], ) -> Result<HMGetResult<'a, A, B>, ValkeyError>
where A: Into<Vec<u8>> + Clone, ValkeyString: Into<B>,

Returns the values associated with the specified fields in the hash stored at this key.

Source

pub fn list_push_head(&self, element: ValkeyString) -> Status

Source

pub fn list_push_tail(&self, element: ValkeyString) -> Status

Source

pub fn list_pop_head(&self) -> Option<ValkeyString>

Source

pub fn list_pop_tail(&self) -> Option<ValkeyString>

Source

pub fn set_expire(&self, expire: Duration) -> ValkeyResult

Source

pub fn remove_expire(&self) -> ValkeyResult

Remove expiration from a key if it exists.

Source

pub fn write(&self, val: &str) -> ValkeyResult

Source

pub fn delete(&self) -> ValkeyResult

§Panics

Will panic if RedisModule_DeleteKey is missing in redismodule.h

§Panics

Will panic if RedisModule_UnlinkKey is missing in redismodule.h

Source

pub fn key_type(&self) -> KeyType

§Panics

Will panic if RedisModule_KeyType is missing in redismodule.h

Source

pub fn open_with_redis_string( ctx: *mut RedisModuleCtx, key: *mut RedisModuleString, ) -> Self

Source

pub fn get_value<'a, 'b, T>( &'a self, redis_type: &ValkeyType, ) -> Result<Option<&'b mut T>, ValkeyError>

§Panics

Will panic if RedisModule_ModuleTypeGetValue is missing in redismodule.h

TODO Avoid clippy warning about needless lifetime as a temporary workaround

Source

pub fn set_value<T>( &self, redis_type: &ValkeyType, value: T, ) -> Result<(), ValkeyError>

§Panics

Will panic if RedisModule_ModuleTypeSetValue is missing in redismodule.h

Source

pub fn trim_stream_by_id( &self, id: RedisModuleStreamID, approx: bool, ) -> Result<usize, ValkeyError>

Trait Implementations§

Source§

impl Drop for ValkeyKeyWritable

Source§

fn drop(&mut self)

Executes the destructor for this 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, 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, 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.