api!() { /* proc-macro */ }
Expand description
This proc macro allows specifying which RedisModuleAPI is required by some valekymodue-rs function. The macro finds, for a given set of RedisModuleAPI, what the minimal Valkey version is that contains all those APIs and decides whether or not the function might raise an [APIError].
In addition, for each RedisModuleAPI, the proc macro injects a code that extracts the actual API function pointer and raises an error or panics if the API is invalid.
§Panics
Panics when an API is not available and if the function doesn’t return Result
. If it does
return a Result
, the panics are replaced with returning a Result::Err
.
§Examples
Creating a wrapper for the [RedisModule_AddPostNotificationJob
]
ⓘ
redismodule_api!(
[RedisModule_AddPostNotificationJob],
pub fn add_post_notification_job<F: Fn(&Context)>(&self, callback: F) -> Status {
let callback = Box::into_raw(Box::new(callback));
unsafe {
RedisModule_AddPostNotificationJob(
self.ctx,
Some(post_notification_job::<F>),
callback as *mut c_void,
Some(post_notification_job_free_callback::<F>),
)
}
.into()
}
);