Skip to content
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

fix #207 add support for RedisModule_GetCurrentCommandName #208

Merged
merged 7 commits into from
Feb 16, 2022

Conversation

gkorland
Copy link
Contributor

No description provided.

@gkorland gkorland linked an issue Dec 28, 2021 that may be closed by this pull request
#[cfg(feature = "experimental-api")]
pub fn current_command_name(&self) -> &str {
unsafe {
CStr::from_ptr(raw::RedisModule_GetCurrentCommandName.unwrap()(self.ctx))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will crash on redis prior to 6.2
(redis/redis#8792)
I suggest to check if available, and if not return "N/A" etc., or even better to allow it to fail.

Comment on lines 285 to 292
#[cfg(feature = "experimental-api")]
pub fn current_command_name(&self) -> &str {
unsafe {
CStr::from_ptr(raw::RedisModule_GetCurrentCommandName.unwrap()(self.ctx))
.to_str()
.unwrap()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[cfg(feature = "experimental-api")]
pub fn current_command_name(&self) -> &str {
unsafe {
CStr::from_ptr(raw::RedisModule_GetCurrentCommandName.unwrap()(self.ctx))
.to_str()
.unwrap()
}
}
pub fn current_command_name(&self) -> Result<String, RedisError> {
#[cfg(feature = "experimental-api")]
unsafe {
match raw::RedisModule_GetCurrentCommandName {
Some(cmd) => Ok(CStr::from_ptr(cmd(self.ctx)).to_str().unwrap().to_string()),
None => Err(RedisError::Str(
"API RedisModule_GetCurrentCommandName is not available",
)),
}
}
#[cfg(not(feature = "experimental-api"))]
Err(RedisError::Str(
"API RedisModule_GetCurrentCommandName requires feature 'experimental-api'",
))
}

@oshadmi oshadmi merged commit 53f494b into master Feb 16, 2022
@oshadmi oshadmi deleted the current_command_name branch February 16, 2022 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for GetCurrentCommandName
3 participants