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

Function emptyDb

src/db.cpp:609–646  ·  view source on GitHub ↗

Remove all keys from all the databases in a Redis DB. * 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 if we

Source from the content-addressed store, hash-verified

607 * database(s). Otherwise -1 is returned in the specific case the
608 * DB number is out of range, and errno is set to EINVAL. */
609long long emptyDb(int dbnum, int flags, void(callback)(void*)) {
610 int async = (flags & EMPTYDB_ASYNC);
611 RedisModuleFlushInfoV1 fi = {REDISMODULE_FLUSHINFO_VERSION,!async,dbnum};
612 long long removed = 0;
613
614 if (dbnum < -1 || dbnum >= cserver.dbnum) {
615 errno = EINVAL;
616 return -1;
617 }
618
619 /* Fire the flushdb modules event. */
620 moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
621 REDISMODULE_SUBEVENT_FLUSHDB_START,
622 &fi);
623
624 /* Make sure the WATCHed keys are affected by the FLUSH* commands.
625 * Note that we need to call the function while the keys are still
626 * there. */
627 signalFlushedDb(dbnum, async);
628
629 /* Empty redis database structure. */
630 removed = emptyDbStructure(g_pserver->db, dbnum, async, callback);
631
632 /* Flush slots to keys map if enable cluster, we can flush entire
633 * slots to keys map whatever dbnum because only support one DB
634 * in cluster mode. */
635 if (g_pserver->cluster_enabled) slotToKeyFlush(async);
636
637 if (dbnum == -1) flushSlaveKeysWithExpireList();
638
639 /* Also fire the end event. Note that this event will fire almost
640 * immediately after the start event if the flush is asynchronous. */
641 moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
642 REDISMODULE_SUBEVENT_FLUSHDB_END,
643 &fi);
644
645 return removed;
646}
647
648/* Store a backup of the database for later use, and put an empty one
649 * instead of it. */

Callers 7

flushAllDataAndResetRDBFunction · 0.85
flushdbCommandFunction · 0.85
clusterResetFunction · 0.85
clusterCommandFunction · 0.85
readSnapshotBulkPayloadFunction · 0.85
readSyncBulkPayloadRdbFunction · 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