| 456 | } |
| 457 | |
| 458 | dict_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 | |
| 478 | dict_iter redisDbPersistentData::find_cached_threadsafe(const char *key) const |
| 479 | { |
no test coverage detected