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
impl ValkeyKeyWritable
pub fn open(ctx: *mut RedisModuleCtx, key: &ValkeyString) -> Self
Sourcepub fn is_empty(&self) -> bool
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)
}
pub fn as_string_dma(&self) -> Result<StringDMA<'_>, ValkeyError>
pub fn hash_set(&self, field: &str, value: ValkeyString) -> Status
pub fn hash_del(&self, field: &str) -> Status
pub fn hash_get(&self, field: &str) -> Result<Option<ValkeyString>, ValkeyError>
Sourcepub fn hash_get_multi<'a, A, B>(
&self,
fields: &'a [A],
) -> Result<HMGetResult<'a, A, B>, ValkeyError>
pub fn hash_get_multi<'a, A, B>( &self, fields: &'a [A], ) -> Result<HMGetResult<'a, A, B>, ValkeyError>
Returns the values associated with the specified fields in the hash stored at this key.
pub fn list_push_head(&self, element: ValkeyString) -> Status
pub fn list_push_tail(&self, element: ValkeyString) -> Status
pub fn list_pop_head(&self) -> Option<ValkeyString>
pub fn list_pop_tail(&self) -> Option<ValkeyString>
pub fn set_expire(&self, expire: Duration) -> ValkeyResult
Sourcepub fn remove_expire(&self) -> ValkeyResult
pub fn remove_expire(&self) -> ValkeyResult
Remove expiration from a key if it exists.
pub fn write(&self, val: &str) -> ValkeyResult
Sourcepub fn delete(&self) -> ValkeyResult
pub fn delete(&self) -> ValkeyResult
§Panics
Will panic if RedisModule_DeleteKey
is missing in redismodule.h
Sourcepub fn unlink(&self) -> ValkeyResult
pub fn unlink(&self) -> ValkeyResult
§Panics
Will panic if RedisModule_UnlinkKey
is missing in redismodule.h
Sourcepub fn key_type(&self) -> KeyType
pub fn key_type(&self) -> KeyType
§Panics
Will panic if RedisModule_KeyType
is missing in redismodule.h
pub fn open_with_redis_string( ctx: *mut RedisModuleCtx, key: *mut RedisModuleString, ) -> Self
Sourcepub fn get_value<'a, 'b, T>(
&'a self,
redis_type: &ValkeyType,
) -> Result<Option<&'b mut T>, ValkeyError>
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
Sourcepub fn set_value<T>(
&self,
redis_type: &ValkeyType,
value: T,
) -> Result<(), ValkeyError>
pub fn set_value<T>( &self, redis_type: &ValkeyType, value: T, ) -> Result<(), ValkeyError>
§Panics
Will panic if RedisModule_ModuleTypeSetValue
is missing in redismodule.h