Skip to content

Commit

Permalink
Move is_empty() in key.rs to its rightful place with the documentatio…
Browse files Browse the repository at this point in the history
…n. (#282)
  • Loading branch information
QuChen88 authored Jan 15, 2024
1 parent 2aafa4a commit b918ed0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,15 @@ impl RedisKeyWritable {
Self { ctx, key_inner }
}

/// Detects whether the value stored in a Redis key is empty.
/// Returns `true` if the key is of type [KeyType::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.
/// # Note
///
/// An empty key can be reliably detected by looking for a null
/// as the key is opened [RedisKeyWritable::open] in read mode,
/// but when asking for a write, Redis 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 redis_module::key::RedisKeyWritable;
Expand All @@ -235,6 +238,11 @@ impl RedisKeyWritable {
/// Ok(is_empty)
/// }
/// ```
#[must_use]
pub fn is_empty(&self) -> bool {
self.key_type() == KeyType::Empty
}

pub fn as_string_dma(&self) -> Result<StringDMA, RedisError> {
StringDMA::new(self)
}
Expand Down Expand Up @@ -361,11 +369,6 @@ impl RedisKeyWritable {
unsafe { raw::RedisModule_KeyType.unwrap()(self.key_inner) }.into()
}

#[must_use]
pub fn is_empty(&self) -> bool {
self.key_type() == KeyType::Empty
}

pub fn open_with_redis_string(
ctx: *mut raw::RedisModuleCtx,
key: *mut raw::RedisModuleString,
Expand Down

0 comments on commit b918ed0

Please sign in to comment.