Thuta Learning
Redis
BasicData & Databasesbeginner

Keys, Namespaces, and SCAN

What you'll walk away with

  • Explain the core ideas behind Keys, Namespaces, and SCAN
  • Run the sample Redis command or code and verify its output
  • Apply the technique correctly to the Tutorial Platform and production scenarios

Build the mental model

A Redis key is a binary-safe string in a global namespace. A pattern such as `app:entity:id:purpose` clarifies ownership and debugging and can include environment or tenant boundaries. `KEYS *` scans the entire dataset at once and can block production. Incremental `SCAN` is safer, but it is not a snapshot and may observe duplicates or miss concurrent changes.

Connect it to a real scenario

Use keys such as `tutorial:42:card`, `session:<token>`, `rate:user:42:<window>`, and `leaderboard:weekly:2026-W35`. Inspect unknown keys with `TYPE`, `TTL`, `MEMORY USAGE`, and `OBJECT ENCODING`, then iterate in batches with `SCAN MATCH tutorial:* COUNT 100`.

Try the working example

shell
SET tutorial:42:card '{"title":"Redis"}' EX 300
TYPE tutorial:42:card
TTL tutorial:42:card
MEMORY USAGE tutorial:42:card
SCAN 0 MATCH tutorial:* COUNT 100
You should see
You get the key type, remaining TTL, memory estimate, and cursor-based scan results.

5-minute try-it

Design a key convention separating development/production and two tenants, then create five example keys.

One important caution

Putting raw user input directly into keys can create unbounded cardinality, collisions, and sensitive-data leaks. Normalize or hash it and enforce limits.

Redis — KeyspaceRedis

Easy traps

  • Putting raw user input directly into keys can create unbounded cardinality, collisions, and sensitive-data leaks. Normalize or hash it and enforce limits.
  • Validate sample commands on a local or test instance with recoverable data before applying them to production Redis.

Exercise

Design a key convention separating development/production and two tenants, then create five example keys.

You'll know it worked when: You get the key type, remaining TTL, memory estimate, and cursor-based scan results.

Keys, Namespaces, and SCAN | Thuta Learning