Typorithm · easy

Hashes

redis-hashesredishashhsetfield
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Hashes

0%

Data Types

A Redis hash maps fields to values under a single key, making it ideal for representing objects like a user record compactly and efficiently.

A hash is a map of field→value pairs stored under one Redis key — a natural fit for objects such as a user, where each field (name, age) holds a value.

HSET writes one or more fields, HGET reads a single field, and HGETALL returns every field and value at once. HINCRBY atomically adds to a numeric field, so age can be bumped without a read-modify-write.

HDEL removes individual fields while leaving the rest of the hash intact. For small objects, hashes are memory-efficient and keep related data grouped under one key.

01

A hash maps field→value under one key.

02

HSET sets fields; HGET reads one.

03

HINCRBY atomically bumps a numeric field.

HSET user:1 name "Ada" age 36
HGET user:1 name
HGETALL user:1
HINCRBY user:1 age 1
HDEL user:1 age

Read the implementation

Connect each part of the code to the concept before you type.

1. Set fields

HSET sets one or more field→value pairs on the hash stored at the key, creating it if needed.

HSET user:1 name "Ada" age 36

2. Get one field

HGET returns the value of a single field within the hash.

HGET user:1 name

3. Get all

HGETALL returns every field and value in the hash as a flat list.

HGETALL user:1

4. Increment field

HINCRBY atomically adds an integer to a numeric field, here bumping age by 1.

HINCRBY user:1 age 1

5. Delete field

HDEL removes one or more fields from the hash without touching the rest.

HDEL user:1 age

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Hashes: Lesson & Practice · Typorithm | ApplyDjinn