Skip to main content

Redis Cheatsheet

Key Concepts

  • a in-memory key-value store, store and retrieve using a unique key
  • can be used as a database, cache, and/or messsage broker
  • supports numbers, strings, hashes, lists, sets, sorted sets

why is it so fast?

  • Redis keeps everything in RAM

How does it manage data?

  • data expirations (set expiration times for keys)
  • data partitioning (divide large datasets into smaller, more manageable chunks)
  • offloading to persistent storage (store less frequently accessed data on disk, snapshots or log files)
  • clustering (distribute across multiple redis instances)

what happens if data in memory grows beyond the configured memory limit?

  • data eviction
    • volatile-lru: evicts the LRU key from among the keys with an expiration set
    • allkeys-lru: evicts the LRU key from all keys
    • volatile-ttl: evicts the key with the nearest expiration time
    • allkeys-random: evicts a random key from all keys
    • volatile-random: evicts a random key from among the keys with an expiration set
    • noeviction: error when memory limit is reached
  • Disk Persistence
    • RDB (Redis Database Backup): snapshot-based persistence method. configure to take period snapshots and save them to disk in binary format
    • AOF (append-only file): this log is written to disk, allow redis to replay the log
      • can be configured to save after every command, every second, or at specific times
    • No Persistence
    • RDB and AOF can be configure to work together

In case of hardware failure or server restarts, what happens?

  • Redis can load data back into memory from disk (from most recent snapshots or append-only-files)