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:
parent
a15a5d7097
commit
089ee5979d
22
src/module.c
22
src/module.c
@ -5891,6 +5891,26 @@ int RM_CommandFilterArgDelete(RedisModuleCommandFilterCtx *fctx, int pos)
|
|||||||
return REDISMODULE_OK;
|
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
|
* Module fork API
|
||||||
* -------------------------------------------------------------------------- */
|
* -------------------------------------------------------------------------- */
|
||||||
@ -6971,4 +6991,6 @@ void moduleRegisterCoreAPI(void) {
|
|||||||
REGISTER_API(BlockClientOnKeys);
|
REGISTER_API(BlockClientOnKeys);
|
||||||
REGISTER_API(SignalKeyAsReady);
|
REGISTER_API(SignalKeyAsReady);
|
||||||
REGISTER_API(GetBlockedClientReadyKey);
|
REGISTER_API(GetBlockedClientReadyKey);
|
||||||
|
REGISTER_API(GetUsedMemoryPercentage);
|
||||||
|
REGISTER_API(MallocSize);
|
||||||
}
|
}
|
||||||
|
@ -633,6 +633,8 @@ int REDISMODULE_API_FUNC(RedisModule_CommandFilterArgDelete)(RedisModuleCommandF
|
|||||||
int REDISMODULE_API_FUNC(RedisModule_Fork)(RedisModuleForkDoneHandler cb, void *user_data);
|
int REDISMODULE_API_FUNC(RedisModule_Fork)(RedisModuleForkDoneHandler cb, void *user_data);
|
||||||
int REDISMODULE_API_FUNC(RedisModule_ExitFromChild)(int retcode);
|
int REDISMODULE_API_FUNC(RedisModule_ExitFromChild)(int retcode);
|
||||||
int REDISMODULE_API_FUNC(RedisModule_KillForkChild)(int child_pid);
|
int REDISMODULE_API_FUNC(RedisModule_KillForkChild)(int child_pid);
|
||||||
|
float REDISMODULE_API_FUNC(RedisModule_GetUsedMemoryPercentage)();
|
||||||
|
size_t REDISMODULE_API_FUNC(RedisModule_MallocSize)(void* ptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define RedisModule_IsAOFClient(id) ((id) == UINT64_MAX)
|
#define RedisModule_IsAOFClient(id) ((id) == UINT64_MAX)
|
||||||
@ -842,6 +844,8 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
|
|||||||
REDISMODULE_GET_API(Fork);
|
REDISMODULE_GET_API(Fork);
|
||||||
REDISMODULE_GET_API(ExitFromChild);
|
REDISMODULE_GET_API(ExitFromChild);
|
||||||
REDISMODULE_GET_API(KillForkChild);
|
REDISMODULE_GET_API(KillForkChild);
|
||||||
|
REDISMODULE_GET_API(GetUsedMemoryPercentage);
|
||||||
|
REDISMODULE_GET_API(MallocSize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (RedisModule_IsModuleNameBusy && RedisModule_IsModuleNameBusy(name)) return REDISMODULE_ERR;
|
if (RedisModule_IsModuleNameBusy && RedisModule_IsModuleNameBusy(name)) return REDISMODULE_ERR;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user