Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub static REDIS_JSON_TYPE: RedisType = RedisType::new(
free: Some(redisjson::type_methods::free),

// Currently unused by Redis
mem_usage: None,
mem_usage: Some(redisjson::type_methods::mem_usage),
digest: None,

// Auxiliary data (v2)
Expand Down
12 changes: 12 additions & 0 deletions src/redisjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ impl RedisJSON {

pub mod type_methods {
use super::*;
use crate::manager::{Manager, RedisJsonKeyManager};
use std::marker::PhantomData;
use std::ptr::null_mut;

pub extern "C" fn rdb_load(rdb: *mut raw::RedisModuleIO, encver: c_int) -> *mut c_void {
Expand Down Expand Up @@ -542,4 +544,14 @@ pub mod type_methods {
let json = &*(value as *mut RedisJSON);
raw::save_string(rdb, &json.data.to_string());
}

#[allow(non_snake_case, unused)]
pub unsafe extern "C" fn mem_usage(value: *const c_void) -> usize {
let json = &*(value as *mut RedisJSON);

let manager = RedisJsonKeyManager {
phantom: PhantomData,
};
manager.get_memory(&json.data).unwrap_or(0)
}
}