Basic Components Implementation Flashcards
1
Q
How to implement LRU / MRU cache?
A
Hash Table + Link list
2
Q
How to implement LFU cache?
A
Hash Table + Sorted List
(similar to Redis sorted set)
3
Q
How to keep records from the last x secs or minutes?
What is the use case for this?
A
Redis Sorted set where the score is the timestamp.
ZREM RANGE BY SCORE
Use case: API Rate Limiting
4
Q
How to keep the rank of all players in a tournament?
A
Redis Sorted set where the score is the points (logN)
ZREM RANGE BY RANK
Use case: Lichess