Reading — step 1 of 3
Key-Value Storage
SET & GET — The Heart of Redis
Redis is fundamentally a key-value store. The two most important commands are:
SET key value— store a value under a keyGET key— retrieve the value, or null if the key doesn't exist
How Redis Stores Data Internally
Under the hood, Redis uses a hash table (dictionary) to map keys to values. This gives O(1) average-case lookup and insertion — the reason Redis is so fast.
In your implementation, you'll use your language's built-in hash map:
- Python:
dict - JavaScript:
Mapor plain object - Go:
map[string]string - Rust:
HashMap<String, String>
RESP Responses
SET always returns a simple string: +OK\r\n
GET returns a bulk string if the key exists:
$5\r\n
hello\r\n
Or a null bulk string if it doesn't:
$-1\r\n
The -1 length is RESP's way of saying "this value doesn't exist" (like null or nil).
Overwriting
Setting a key that already exists overwrites the previous value silently. There's no error — this is by design. Redis treats SET as an upsert.
SET name Alice → +OK
SET name Bob → +OK
GET name → $3\r\nBob\r\n
Your Task
Add SET and GET to your growing Redis implementation. You'll need a hash map to store the data.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…