Key-value stores

The key-value model on Redis: basic commands, five value types, key naming, expiry and eviction, and what the model forbids: finding data by its content.

  • 24 cards
  • 5 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. Sort and link
  4. Scenarios
  5. Understand

A few cards from the deck

  • Key-value store: what is it?

    Show the answer

    A database that files each piece of data under a unique name and can only fetch it by that name; the stored content stays opaque to it.

    This very simple model makes reads and writes extremely fast, but you cannot ask for "every value that contains this word".

  • What does the server answer to the last command?

    ```text
    SET compteur 10
    INCR compteur
    INCR compteur
    GET compteur
    `

    • "12"
    • "10"
    • (integer) 12
    • (nil)
    Show the answer

    "12"

    INCR adds 1 on each call: 10, then 11, then 12. GET always returns the value's text, which redis-cli shows in quotes; only INCR answers with an integer.

  • To store a token that must vanish by itself after 30 seconds, you give it a … with the … command.

    Show the answer

    To store a token that must vanish by itself after 30 seconds, you give it a time to live with the EXPIRE command.

    SET jeton abc EX 30 does both in a single atomic command: writing the value and setting the time to live.

  • Time to live (TTL): what is it?

    Show the answer

    A delay, in seconds, after which the server deletes by itself an entry it was attached to.

    EXPIRE session 60 sets it, TTL session gives the time left: -1 if the key never expires, -2 if it does not exist (any more).

  • A Redis cache refuses writes with "OOM command not allowed when used memory > 'maxmemory'". The keys have no time to live. Which fix is right?

    • Set maxmemory to 0 so that memory is no longer limited
    • Give the keys a time to live and pick the allkeys-lru eviction
    • Add an index on the values so that they are found faster
    • Restart the server every night so that its memory is emptied
    Show the answer

    Give the keys a time to live and pick the allkeys-lru eviction

    With the default noeviction policy, a full server refuses to write rather than delete anything. Times to live let stale entries leave on their own, and allkeys-lru evicts the rest when needed. With no limit, a cache that never drops anything grows until it exhausts the machine's memory.