Modules: context flags now include OOM flag.

Plus freeMemoryIfNeeded() refactoring to improve legibility.
Please review this commit for sanity.
This commit is contained in:
antirez
2018-04-09 17:43:50 +02:00
parent 6888c1a10d
commit f97efe0cac
4 changed files with 69 additions and 34 deletions

View File

@ -1327,6 +1327,9 @@ int RM_GetSelectedDb(RedisModuleCtx *ctx) {
*
* * REDISMODULE_CTX_FLAGS_EVICT: Maxmemory is set and has an eviction
* policy that may delete keys
*
* * REDISMODULE_CTX_FLAGS_OOM: Redis is out of memory according to the
* maxmemory setting.
*/
int RM_GetContextFlags(RedisModuleCtx *ctx) {
@ -1365,6 +1368,11 @@ int RM_GetContextFlags(RedisModuleCtx *ctx) {
flags |= REDISMODULE_CTX_FLAGS_READONLY;
}
/* OOM flag. */
if (getMaxmemoryState(NULL,NULL,NULL) == C_ERR) {
flags |= REDISMODULE_CTX_FLAGS_OOM;
}
return flags;
}