MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / RM_GetContextFlags

Function RM_GetContextFlags

src/module.cpp:2175–2256  ·  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

2173 * background child process.
2174 */
2175int RM_GetContextFlags(RedisModuleCtx *ctx) {
2176 int flags = 0;
2177
2178 /* Client specific flags */
2179 if (ctx) {
2180 if (ctx->client) {
2181 if (ctx->client->flags & CLIENT_DENY_BLOCKING)
2182 flags |= REDISMODULE_CTX_FLAGS_DENY_BLOCKING;
2183 /* Module command received from MASTER, is replicated. */
2184 if (ctx->client->flags & CLIENT_MASTER)
2185 flags |= REDISMODULE_CTX_FLAGS_REPLICATED;
2186 }
2187
2188 /* For DIRTY flags, we need the blocked client if used */
2189 client *c = ctx->blocked_client ? ctx->blocked_client->client : ctx->client;
2190 if (c && (c->flags & (CLIENT_DIRTY_CAS|CLIENT_DIRTY_EXEC))) {
2191 flags |= REDISMODULE_CTX_FLAGS_MULTI_DIRTY;
2192 }
2193 }
2194
2195 if (serverTL->in_eval)
2196 flags |= REDISMODULE_CTX_FLAGS_LUA;
2197
2198 if (serverTL->in_exec)
2199 flags |= REDISMODULE_CTX_FLAGS_MULTI;
2200
2201 if (g_pserver->cluster_enabled)
2202 flags |= REDISMODULE_CTX_FLAGS_CLUSTER;
2203
2204 if (g_pserver->loading)
2205 flags |= REDISMODULE_CTX_FLAGS_LOADING;
2206
2207 /* Maxmemory and eviction policy */
2208 if (g_pserver->maxmemory > 0 && (!listLength(g_pserver->masters) || !g_pserver->repl_slave_ignore_maxmemory)) {
2209 flags |= REDISMODULE_CTX_FLAGS_MAXMEMORY;
2210
2211 if (g_pserver->maxmemory_policy != MAXMEMORY_NO_EVICTION)
2212 flags |= REDISMODULE_CTX_FLAGS_EVICT;
2213 }
2214
2215 /* Persistence flags */
2216 if (g_pserver->aof_state != AOF_OFF)
2217 flags |= REDISMODULE_CTX_FLAGS_AOF;
2218 if (g_pserver->saveparamslen > 0)
2219 flags |= REDISMODULE_CTX_FLAGS_RDB;
2220
2221 /* Replication flags */
2222 if (listLength(g_pserver->masters) == 0) {
2223 flags |= REDISMODULE_CTX_FLAGS_MASTER;
2224 } else {
2225 flags |= REDISMODULE_CTX_FLAGS_SLAVE;
2226 if (g_pserver->repl_slave_ro)
2227 flags |= REDISMODULE_CTX_FLAGS_READONLY;
2228
2229 /* Replica state flags. */
2230 redisMaster *mi = (redisMaster*)listFirst(g_pserver->masters);
2231 if (mi->repl_state == REPL_STATE_CONNECT ||
2232 mi->repl_state == REPL_STATE_CONNECTING)

Callers

nothing calls this directly

Calls 2

getMaxmemoryStateFunction · 0.85
hasActiveChildProcessFunction · 0.85

Tested by

no test coverage detected