-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathload_unload.rs
45 lines (38 loc) · 1.18 KB
/
load_unload.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use valkey_module::alloc::ValkeyAlloc;
use valkey_module::{logging::ValkeyLogLevel, valkey_module, Context, Status, ValkeyString};
static mut GLOBAL_STATE: Option<String> = None;
fn init(ctx: &Context, args: &[ValkeyString]) -> Status {
let (before, after) = unsafe {
let before = GLOBAL_STATE.clone();
GLOBAL_STATE.replace(format!("Args passed: {}", args.join(", ")));
let after = GLOBAL_STATE.clone();
(before, after)
};
ctx.log(
ValkeyLogLevel::Warning,
&format!("Update global state on LOAD. BEFORE: {before:?}, AFTER: {after:?}",),
);
Status::Ok
}
fn deinit(ctx: &Context) -> Status {
let (before, after) = unsafe {
let before = GLOBAL_STATE.take();
let after = GLOBAL_STATE.clone();
(before, after)
};
ctx.log(
ValkeyLogLevel::Warning,
&format!("Update global state on UNLOAD. BEFORE: {before:?}, AFTER: {after:?}"),
);
Status::Ok
}
//////////////////////////////////////////////////////
valkey_module! {
name: "load_unload",
version: 1,
allocator: (ValkeyAlloc, ValkeyAlloc),
data_types: [],
init: init,
deinit: deinit,
commands: [],
}