Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
fef1e63c
Unverified
Commit
fef1e63c
authored
Nov 21, 2019
by
Salvatore Sanfilippo
Committed by
GitHub
Nov 21, 2019
Browse files
Merge pull request #6346 from MeirShpilraien/expose_zmalloc_capabilities
Expose used memory to modules via redismodule api
parents
c697edf4
70469b76
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
fef1e63c
...
@@ -5995,6 +5995,26 @@ int RM_CommandFilterArgDelete(RedisModuleCommandFilterCtx *fctx, int pos)
...
@@ -5995,6 +5995,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_GetUsedMemoryRatio
(){
float
level
;
getMaxmemoryState
(
NULL
,
NULL
,
NULL
,
&
level
);
return
level
;
}
/* --------------------------------------------------------------------------
/* --------------------------------------------------------------------------
* Scanning keyspace and hashes
* Scanning keyspace and hashes
* -------------------------------------------------------------------------- */
* -------------------------------------------------------------------------- */
...
@@ -7360,6 +7380,8 @@ void moduleRegisterCoreAPI(void) {
...
@@ -7360,6 +7380,8 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API
(
BlockClientOnKeys
);
REGISTER_API
(
BlockClientOnKeys
);
REGISTER_API
(
SignalKeyAsReady
);
REGISTER_API
(
SignalKeyAsReady
);
REGISTER_API
(
GetBlockedClientReadyKey
);
REGISTER_API
(
GetBlockedClientReadyKey
);
REGISTER_API
(
GetUsedMemoryRatio
);
REGISTER_API
(
MallocSize
);
REGISTER_API
(
ScanCursorCreate
);
REGISTER_API
(
ScanCursorCreate
);
REGISTER_API
(
ScanCursorDestroy
);
REGISTER_API
(
ScanCursorDestroy
);
REGISTER_API
(
ScanCursorRestart
);
REGISTER_API
(
ScanCursorRestart
);
...
...
src/redismodule.h
View file @
fef1e63c
...
@@ -649,6 +649,8 @@ int REDISMODULE_API_FUNC(RedisModule_CommandFilterArgDelete)(RedisModuleCommandF
...
@@ -649,6 +649,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_GetUsedMemoryRatio
)();
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)
...
@@ -871,6 +873,8 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
...
@@ -871,6 +873,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
(
GetUsedMemoryRatio
);
REDISMODULE_GET_API
(
MallocSize
);
#endif
#endif
if
(
RedisModule_IsModuleNameBusy
&&
RedisModule_IsModuleNameBusy
(
name
))
return
REDISMODULE_ERR
;
if
(
RedisModule_IsModuleNameBusy
&&
RedisModule_IsModuleNameBusy
(
name
))
return
REDISMODULE_ERR
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment