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

Function emptyDb

app/redis-6.2.6/src/db.c:426–463  ·  view source on GitHub ↗

Remove all keys from all the databases in a Redis server. * If callback is given the function is called from time to time to * signal that work is in progress. * * The dbnum can be -1 if all the DBs should be flushed, or the specified * DB number if we want to flush only a single Redis database number. * * Flags are be EMPTYDB_NO_FLAGS if no special flags are specified or * EMPTYDB_ASYNC i

Source from the content-addressed store, hash-verified

424 * database(s). Otherwise -1 is returned in the specific case the
425 * DB number is out of range, and errno is set to EINVAL. */
426long long emptyDb(int dbnum, int flags, void(callback)(void*)) {
427 int async = (flags & EMPTYDB_ASYNC);
428 RedisModuleFlushInfoV1 fi = {REDISMODULE_FLUSHINFO_VERSION,!async,dbnum};
429 long long removed = 0;
430
431 if (dbnum < -1 || dbnum >= server.dbnum) {
432 errno = EINVAL;
433 return -1;
434 }
435
436 /* Fire the flushdb modules event. */
437 moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
438 REDISMODULE_SUBEVENT_FLUSHDB_START,
439 &fi);
440
441 /* Make sure the WATCHed keys are affected by the FLUSH* commands.
442 * Note that we need to call the function while the keys are still
443 * there. */
444 signalFlushedDb(dbnum, async);
445
446 /* Empty redis database structure. */
447 removed = emptyDbStructure(server.db, dbnum, async, callback);
448
449 /* Flush slots to keys map if enable cluster, we can flush entire
450 * slots to keys map whatever dbnum because only support one DB
451 * in cluster mode. */
452 if (server.cluster_enabled) slotToKeyFlush(async);
453
454 if (dbnum == -1) flushSlaveKeysWithExpireList();
455
456 /* Also fire the end event. Note that this event will fire almost
457 * immediately after the start event if the flush is asynchronous. */
458 moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
459 REDISMODULE_SUBEVENT_FLUSHDB_END,
460 &fi);
461
462 return removed;
463}
464
465/* Store a backup of the database for later use, and put an empty one
466 * instead of it. */

Callers 5

readSyncBulkPayloadFunction · 0.85
flushAllDataAndResetRDBFunction · 0.85
flushdbCommandFunction · 0.85
clusterResetFunction · 0.85
debugCommandFunction · 0.85

Calls 5

moduleFireServerEventFunction · 0.85
signalFlushedDbFunction · 0.85
emptyDbStructureFunction · 0.85
slotToKeyFlushFunction · 0.85

Tested by

no test coverage detected