redis_module/context/
blocked.rs

1use std::ptr;
2
3use crate::raw;
4use crate::Context;
5
6pub struct BlockedClient {
7    pub(crate) inner: *mut raw::RedisModuleBlockedClient,
8}
9
10// We need to be able to send the inner pointer to another thread
11unsafe impl Send for BlockedClient {}
12
13impl Drop for BlockedClient {
14    fn drop(&mut self) {
15        unsafe { raw::RedisModule_UnblockClient.unwrap()(self.inner, ptr::null_mut()) };
16    }
17}
18
19impl Context {
20    #[must_use]
21    pub fn block_client(&self) -> BlockedClient {
22        let blocked_client = unsafe {
23            raw::RedisModule_BlockClient.unwrap()(
24                self.ctx, // ctx
25                None,     // reply_func
26                None,     // timeout_func
27                None, 0,
28            )
29        };
30
31        BlockedClient {
32            inner: blocked_client,
33        }
34    }
35}