-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to delete hash fields #130
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,11 @@ extern "C" { | |
|
||
pub const FMT: *const c_char = b"v\0".as_ptr() as *const c_char; | ||
|
||
// REDISMODULE_HASH_DELETE is defined explicitly here because bindgen cannot | ||
// parse typecasts in C macro constants yet. | ||
// See https://github.com/rust-lang/rust-bindgen/issues/316 | ||
pub const REDISMODULE_HASH_DELETE: *const RedisModuleString = 1 as *const RedisModuleString; | ||
|
||
// Helper functions for the raw bindings. | ||
|
||
pub fn call_reply_type(reply: *mut RedisModuleCallReply) -> ReplyType { | ||
|
@@ -348,6 +353,25 @@ pub fn hash_set(key: *mut RedisModuleKey, field: &str, value: *mut RedisModuleSt | |
} | ||
} | ||
|
||
pub fn hash_del(key: *mut RedisModuleKey, field: &str) -> Status { | ||
let field = CString::new(field).unwrap(); | ||
|
||
// TODO: Add hash_del_multi() | ||
// Support to pass multiple fields is desired but is complicated. | ||
// See hash_get_multi() and https://github.com/redis/redis/issues/7860 | ||
|
||
unsafe { | ||
RedisModule_HashSet.unwrap()( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like the I'm very new to Rust. I don't know where to draw the line between this project providing a user-friendly Rust API to modules vs this project being a very thin and pass-through wrapper around the C modules API. Does it make sense to extend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The aim of this module is to provide an idiomatic Rust API for the Redis modules API. Using flag arguments to fundamentally change the functionality of a method isn't very common even in C, doubly so in Rust; so I think the approach you took here is the right one. One thing I would change is rename all the instances of Oh, and thank you for the PR! |
||
key, | ||
REDISMODULE_HASH_CFIELDS as i32, | ||
field.as_ptr(), | ||
REDISMODULE_HASH_DELETE, | ||
ptr::null::<c_char>(), | ||
) | ||
.into() | ||
} | ||
} | ||
|
||
// Returns pointer to the C string, and sets len to its length | ||
pub fn string_ptr_len(s: *mut RedisModuleString, len: *mut size_t) -> *const c_char { | ||
unsafe { RedisModule_StringPtrLen.unwrap()(s, len) } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to figure out why this was needed -- I expected
bindgen
to generate this automatically.It turns out it doesn't because it can't parse the typecast, see rust-lang/rust-bindgen#316.
Please add a comment here that mentions this.