MCPcopy Create free account
hub / github.com/F-Stack/f-stack / RM_GetContextFlags

Function RM_GetContextFlags

app/redis-6.2.6/src/module.c:2096–2176  ·  view source on GitHub ↗

Return the current context's flags. The flags provide information on the * current request context (whether the client is a Lua script or in a MULTI), * and about the Redis instance in general, i.e replication and persistence. * * It is possible to call this function even with a NULL context, however * in this case the following flags will not be reported: * * * LUA, MULTI, REPLICATED, DIR

Source from the content-addressed store, hash-verified

2094 * background child process.
2095 */
2096int RM_GetContextFlags(RedisModuleCtx *ctx) {
2097 int flags = 0;
2098
2099 /* Client specific flags */
2100 if (ctx) {
2101 if (ctx->client) {
2102 if (ctx->client->flags & CLIENT_DENY_BLOCKING)
2103 flags |= REDISMODULE_CTX_FLAGS_DENY_BLOCKING;
2104 /* Module command received from MASTER, is replicated. */
2105 if (ctx->client->flags & CLIENT_MASTER)
2106 flags |= REDISMODULE_CTX_FLAGS_REPLICATED;
2107 }
2108
2109 /* For DIRTY flags, we need the blocked client if used */
2110 client *c = ctx->blocked_client ? ctx->blocked_client->client : ctx->client;
2111 if (c && (c->flags & (CLIENT_DIRTY_CAS|CLIENT_DIRTY_EXEC))) {
2112 flags |= REDISMODULE_CTX_FLAGS_MULTI_DIRTY;
2113 }
2114 }
2115
2116 if (server.in_eval)
2117 flags |= REDISMODULE_CTX_FLAGS_LUA;
2118
2119 if (server.in_exec)
2120 flags |= REDISMODULE_CTX_FLAGS_MULTI;
2121
2122 if (server.cluster_enabled)
2123 flags |= REDISMODULE_CTX_FLAGS_CLUSTER;
2124
2125 if (server.loading)
2126 flags |= REDISMODULE_CTX_FLAGS_LOADING;
2127
2128 /* Maxmemory and eviction policy */
2129 if (server.maxmemory > 0 && (!server.masterhost || !server.repl_slave_ignore_maxmemory)) {
2130 flags |= REDISMODULE_CTX_FLAGS_MAXMEMORY;
2131
2132 if (server.maxmemory_policy != MAXMEMORY_NO_EVICTION)
2133 flags |= REDISMODULE_CTX_FLAGS_EVICT;
2134 }
2135
2136 /* Persistence flags */
2137 if (server.aof_state != AOF_OFF)
2138 flags |= REDISMODULE_CTX_FLAGS_AOF;
2139 if (server.saveparamslen > 0)
2140 flags |= REDISMODULE_CTX_FLAGS_RDB;
2141
2142 /* Replication flags */
2143 if (server.masterhost == NULL) {
2144 flags |= REDISMODULE_CTX_FLAGS_MASTER;
2145 } else {
2146 flags |= REDISMODULE_CTX_FLAGS_SLAVE;
2147 if (server.repl_slave_ro)
2148 flags |= REDISMODULE_CTX_FLAGS_READONLY;
2149
2150 /* Replica state flags. */
2151 if (server.repl_state == REPL_STATE_CONNECT ||
2152 server.repl_state == REPL_STATE_CONNECTING)
2153 {

Callers

nothing calls this directly

Calls 2

getMaxmemoryStateFunction · 0.85
hasActiveChildProcessFunction · 0.85

Tested by

no test coverage detected