mirror of
https://github.com/fluencelabs/redis
synced 2025-06-14 17:51:21 +00:00
expose used memory via redismodule api
The exposed functions: 1. RedisModule_GetUsedMemoryPercentage - return the used memory 2. RedisModue_MallocSize - return for a given pointer, the amount of memory allocated for this pointer
This commit is contained in:
22
src/module.c
22
src/module.c
@ -5891,6 +5891,26 @@ int RM_CommandFilterArgDelete(RedisModuleCommandFilterCtx *fctx, int pos)
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* For a given pointer, return The amount of memory
|
||||
* allocated for this pointer.
|
||||
*/
|
||||
size_t RM_MallocSize(void* ptr){
|
||||
return zmalloc_size(ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the a number between 0 to 1 indicating
|
||||
* the amount of memory currently used.
|
||||
* 0 - no memory limit
|
||||
* 1 and above, memory limit reached.
|
||||
*/
|
||||
float RM_GetUsedMemoryPercentage(){
|
||||
float level;
|
||||
getMaxmemoryState(NULL, NULL, NULL, &level);
|
||||
return level;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* Module fork API
|
||||
* -------------------------------------------------------------------------- */
|
||||
@ -6971,4 +6991,6 @@ void moduleRegisterCoreAPI(void) {
|
||||
REGISTER_API(BlockClientOnKeys);
|
||||
REGISTER_API(SignalKeyAsReady);
|
||||
REGISTER_API(GetBlockedClientReadyKey);
|
||||
REGISTER_API(GetUsedMemoryPercentage);
|
||||
REGISTER_API(MallocSize);
|
||||
}
|
||||
|
Reference in New Issue
Block a user