Struct RedisKeyWritable

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

RedisKeyWritable is an abstraction over a Redis key that allows read and write operations.

Implementations§

Source§

impl RedisKeyWritable

Source

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

Source

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

Detects whether the value stored in a Redis key is empty.

Note that an empty key can be reliably detected by looking for a null as you open the key in read mode, but when asking for write Redis returns a non-null pointer to allow us to write to even an empty key, so we have to check the key’s value instead.

use redis_module::key::RedisKeyWritable;
use redis_module::RedisError;

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

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

Source

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

Source

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

Source

pub fn hash_get_multi<'a, A, B>( &self, fields: &'a [A], ) -> Result<HMGetResult<'a, A, B>, RedisError>
where A: Into<Vec<u8>> + Clone, RedisString: 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: RedisString) -> Status

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn delete(&self) -> RedisResult

§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 is_empty(&self) -> bool

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: &RedisType, ) -> Result<Option<&'b mut T>, RedisError>

§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: &RedisType, value: T, ) -> Result<(), RedisError>

§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, RedisError>

Trait Implementations§

Source§

impl Drop for RedisKeyWritable

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.