redis-module 2.0.7

A toolkit for building Redis modules in Rust
Documentation
use redis_module::{logging::RedisLogLevel, redis_module, Context, RedisString, Status};

static mut GLOBAL_STATE: Option<String> = None;

fn init(ctx: &Context, args: &[RedisString]) -> 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(
        RedisLogLevel::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(
        RedisLogLevel::Warning,
        &format!("Update global state on UNLOAD. BEFORE: {before:?}, AFTER: {after:?}"),
    );

    Status::Ok
}

//////////////////////////////////////////////////////

redis_module! {
    name: "load_unload",
    version: 1,
    allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
    data_types: [],
    init: init,
    deinit: deinit,
    commands: [],
}