The Suspect Profile
Concept:
Redis Hashes store multiple field-value pairs under one key — like a mini-object or row. In production, they are used for user profiles (one hash per user with fields like name, email, role), shopping carts (product IDs as fields, quantities as values), and configuration stores. The advantage over Strings: you can read or update a single field (HGET, HSET) without fetching the whole object. This makes Hashes memory-efficient and fast for structured data that changes field by field.
Detective Indecks:
I've got names, but names aren't enough. I need profiles—age, height, occupation, where they were last seen. The full picture.
REDIS:
You need Hashes, detective. Think of them as file folders—one key holds multiple related pieces of information. Perfect for suspect profiles.
Detective Indecks:
Show me how it works.
REDIS:
Use `HSET` to build the profile. For example: `HSET suspect:charlie age 34 height "5'9" occupation "mechanic"`. One command, multiple facts. Clean and organized.
Detective Indecks:
And when I need specific information?
REDIS:
`HGET suspect:charlie age` gives you just the age. `HGET suspect:charlie occupation` gives you just the job. Targeted retrieval—no digging through paperwork.
Detective Indecks:
What if I want the whole file?
REDIS:
`HGETALL suspect:charlie` dumps everything—every field and value in the profile. Perfect for briefings or when you need the complete picture.
Detective Indecks:
And if information becomes irrelevant?
REDIS:
`HDEL suspect:charlie occupation` removes just that field. Maybe their job doesn't matter to the case, but you keep the rest. Surgical precision.
Detective Indecks:
Perfect. Time to build some comprehensive profiles and crack this case.
Example Code:
HSET suspect:charlie age 34 height "5'9" last_seen "downtown_pier"
HGET suspect:charlie age
HGETALL suspect:charlie
Your Assignment
Create a comprehensive profile for suspect_delta with age 28, height 5'7", occupation lawyer, and last_seen courthouse. Then retrieve just their occupation.
Redis Console
redis>