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