forked from RedisLabsModules/redismodule-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.rs
30 lines (25 loc) · 824 Bytes
/
block.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use redis_module::{
redis_module, Context, RedisResult, RedisString, RedisValue, ThreadSafeContext,
};
use std::thread;
use std::time::Duration;
fn block(ctx: &Context, _args: Vec<RedisString>) -> RedisResult {
let blocked_client = ctx.block_client();
thread::spawn(move || {
let thread_ctx = ThreadSafeContext::with_blocked_client(blocked_client);
thread::sleep(Duration::from_millis(1000));
thread_ctx.reply(Ok("42".into()));
});
// We will reply later, from the thread
Ok(RedisValue::NoReply)
}
//////////////////////////////////////////////////////
redis_module! {
name: "block",
version: 1,
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["block", block, "", 0, 0, 0],
],
}