File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -50,11 +50,14 @@ impl Command for AllocSetCommand {
5050 // 1. Open key [OK]
5151 // 2. Allocate data [OK]
5252 // 3. Set the key to the data [OK]
53- // 4. Activate custom allocator and compare Redis memory usage
53+ // 4. Activate custom allocator and compare Redis memory usage [OK]
54+ // 5. Handle deallocation of existing value
5455
5556 let key = r. open_key_writable ( key) ;
5657 key. check_type ( & MY_TYPE ) ?;
5758
59+ // TODO: If there is an existing value, reuse it or deallocate it.
60+
5861 let my = Box :: into_raw ( Box :: new (
5962 MyType {
6063 data : "A" . repeat ( size as usize )
@@ -176,6 +179,9 @@ pub extern "C" fn AllocDelCommand_Redis(
176179fn module_on_load ( ctx : * mut raw:: RedisModuleCtx ) -> Result < ( ) , & ' static str > {
177180 module_init ( ctx, MODULE_NAME , MODULE_VERSION ) ?;
178181
182+ // TODO: Call this from inside module_init
183+ redismodule:: use_redis_alloc ( ) ;
184+
179185 MY_TYPE . create_data_type ( ctx, "mytype123" ) ?;
180186
181187 AllocSetCommand :: create ( ctx) ?;
Original file line number Diff line number Diff line change @@ -67,6 +67,11 @@ unsafe impl GlobalAlloc for RedisAlloc {
6767
6868#[ global_allocator]
6969static ALLOC : RedisAlloc = RedisAlloc ;
70+
71+ pub fn use_redis_alloc ( ) {
72+ eprintln ! ( "Using Redis allocator" ) ;
73+ USE_REDIS_ALLOC . store ( true , SeqCst ) ;
74+ }
7075////////////////////////////////////////////////////////////
7176
7277
You can’t perform that action at this time.
0 commit comments