Skip to content
HSET & HGET — Field-Level Storage
step 1/3

Reading — step 1 of 3

Hash Maps

~1 min readHashes

HSET & HGET — Field-Level Storage

Redis hashes store field-value pairs under a single key — like a nested dictionary.

Commands

  • HSET key field value [field value ...] — set fields, return count of new fields added
  • HGET key field — return field value as bulk string, or $-1 if missing

Multi-field HSET

HSET user name Alice age 30 city NYC sets three fields at once, returns :3 (all new).

Updating existing fields: HSET user age 31 returns :0 (no new fields, just updated).

Use Cases

Hashes are perfect for objects:

  • User profiles: HSET user:123 name Alice email [email protected]
  • Counters per category: HINCRBY stats page_views 1
  • Configuration: HSET config max_retries 3 timeout 5000

Implementation

Store hashes as a map of maps: hashes = {key: {field: value, ...}}

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…