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

Method random_cache_threadsafe

src/snapshot.cpp:458–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

456}
457
458dict_iter redisDbPersistentDataSnapshot::random_cache_threadsafe(bool fPrimaryOnly) const
459{
460 if (size() == 0)
461 return dict_iter(nullptr);
462 if (!fPrimaryOnly && m_pdbSnapshot != nullptr && m_pdbSnapshot->size() > 0)
463 {
464 dict_iter iter(nullptr);
465 double pctInSnapshot = (double)m_pdbSnapshot->size() / (size() + m_pdbSnapshot->size());
466 double randval = (double)rand()/RAND_MAX;
467 if (randval <= pctInSnapshot)
468 {
469 return m_pdbSnapshot->random_cache_threadsafe();
470 }
471 }
472 if (dictSize(m_pdict) == 0)
473 return dict_iter(nullptr);
474 dictEntry *de = dictGetRandomKey(m_pdict);
475 return dict_iter(m_pdict, de);
476}
477
478dict_iter redisDbPersistentData::find_cached_threadsafe(const char *key) const
479{

Callers 2

randomMethod · 0.80
performEvictionsFunction · 0.80

Calls 3

dict_iterClass · 0.85
dictGetRandomKeyFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected