-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for DEBUG DIGEST module data type callback (#21)
* Support for DEBUG DIGEST module data type callback Signed-off-by: Nihal Mehta <[email protected]> * Update test cases Signed-off-by: Nihal Mehta <[email protected]> * Move digest to wrapper Signed-off-by: Nihal Mehta <[email protected]> * Update tests Signed-off-by: Nihal Mehta <[email protected]> * Add more scenarios for debug test Signed-off-by: Nihal Mehta <[email protected]> * Clean code and add scenario for debug test Signed-off-by: Nihal Mehta <[email protected]> --------- Signed-off-by: Nihal Mehta <[email protected]>
- Loading branch information
1 parent
a33e0e3
commit 7c25468
Showing
12 changed files
with
206 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use std::os::raw::c_char; | ||
use valkey_module::raw; | ||
use valkey_module::ValkeyString; | ||
|
||
/// `Digest` is a high-level rust interface to the Valkey module C API | ||
/// abstracting away the raw C ffi calls. | ||
pub struct Digest { | ||
pub dig: *mut raw::RedisModuleDigest, | ||
} | ||
|
||
impl Digest { | ||
pub const fn new(dig: *mut raw::RedisModuleDigest) -> Self { | ||
Self { dig } | ||
} | ||
|
||
/// Returns the key name of this [`Digest`]. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Will panic if `RedisModule_GetKeyNameFromDigest` is missing in redismodule.h | ||
pub fn get_key_name(&self) -> ValkeyString { | ||
ValkeyString::from_redis_module_string(std::ptr::null_mut(), unsafe { | ||
raw::RedisModule_GetKeyNameFromDigest | ||
.expect("RedisModule_GetKeyNameFromDigest is not available.")(self.dig) | ||
.cast_mut() | ||
}) | ||
} | ||
|
||
/// Returns the database ID of this [`Digest`]. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Will panic if `RedisModule_GetDbIdFromDigest` is missing in redismodule.h | ||
pub fn get_db_id(&self) -> i32 { | ||
unsafe { | ||
raw::RedisModule_GetDbIdFromDigest | ||
.expect("RedisModule_GetDbIdFromDigest is not available.")(self.dig) | ||
} | ||
} | ||
|
||
/// Adds a new element to this [`Digest`]. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Will panic if `RedisModule_DigestAddStringBuffer` is missing in redismodule.h | ||
pub fn add_string_buffer(&mut self, ele: &[u8]) { | ||
unsafe { | ||
raw::RedisModule_DigestAddStringBuffer | ||
.expect("RedisModule_DigestAddStringBuffer is not available.")( | ||
self.dig, | ||
ele.as_ptr().cast::<c_char>(), | ||
ele.len(), | ||
) | ||
} | ||
} | ||
|
||
/// Similar to [`Digest::add_string_buffer`], but takes [`i64`]. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Will panic if `RedisModule_DigestAddLongLong` is missing in redismodule.h | ||
pub fn add_long_long(&mut self, ll: i64) { | ||
unsafe { | ||
raw::RedisModule_DigestAddLongLong | ||
.expect("RedisModule_DigestAddLongLong is not available.")(self.dig, ll) | ||
} | ||
} | ||
|
||
/// Ends the current sequence in this [`Digest`]. | ||
/// | ||
/// # Panics | ||
/// | ||
/// Will panic if `RedisModule_DigestEndSequence` is missing in redismodule.h | ||
pub fn end_sequence(&mut self) { | ||
unsafe { | ||
raw::RedisModule_DigestEndSequence | ||
.expect("RedisModule_DigestEndSequence is not available.")(self.dig) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod bloom_callback; | ||
pub mod digest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters