SteelReed

Search

Search posts, questions…

Caching & RedisQuestion 7 / 24

Junior

What are Redis's main data types, and what problem does each one solve?

Short answer

Redis is an in-memory key-value store with built-in data structures: caching, sessions, counters, rate limiting, locks, leaderboards, light queues. Pick the right type and each operation is one O(1) or O(log N) command on the server.

cache, counter, lockedit single fieldsunique membersranking, delay queuelog with consumer groupsWhat is the problem?StringHashSetSorted setStream

3 points to say:

  1. Pick the type so the operation is one atomic server-side command, instead of reading the whole object into the app and writing it back.
  2. Hash for editing single fields, JSON string for reading and writing as a whole; small hashes are stored as a very compact listpack.
  3. Sorted set = skiplist + hashtable: ZADD/ZRANK in O(log N), a fit for leaderboards and delay queues.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.