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

Function flushdbCommand

src/db.cpp:831–859  ·  view source on GitHub ↗

FLUSHDB [ASYNC] * * Flushes the currently SELECTed Redis DB. */

Source from the content-addressed store, hash-verified

829 *
830 * Flushes the currently SELECTed Redis DB. */
831void flushdbCommand(client *c) {
832 int flags;
833
834 if (c->argc == 2)
835 {
836 if (!strcasecmp(szFromObj(c->argv[1]), "cache"))
837 {
838 if (g_pserver->m_pstorageFactory == nullptr)
839 {
840 addReplyError(c, "Cannot flush cache without a storage provider set");
841 return;
842 }
843 c->db->removeAllCachedValues();
844 addReply(c,shared.ok);
845 return;
846 }
847 }
848
849 if (getFlushCommandFlags(c,&flags) == C_ERR) return;
850 g_pserver->dirty += emptyDb(c->db->id,flags,NULL);
851 addReply(c,shared.ok);
852#if defined(USE_JEMALLOC)
853 /* jemalloc 5 doesn't release pages back to the OS when there's no traffic.
854 * for large databases, flushdb blocks for long anyway, so a bit more won't
855 * harm and this way the flush and purge will be synchroneus. */
856 if (!(flags & EMPTYDB_ASYNC))
857 jemalloc_purge();
858#endif
859}
860
861/* FLUSHALL [ASYNC]
862 *

Callers

nothing calls this directly

Calls 7

szFromObjFunction · 0.85
addReplyErrorFunction · 0.85
addReplyFunction · 0.85
getFlushCommandFlagsFunction · 0.85
emptyDbFunction · 0.85
jemalloc_purgeFunction · 0.85
removeAllCachedValuesMethod · 0.80

Tested by

no test coverage detected