Video in progress

How should you structure key names in Redis?

Use a readable namespace separated by colons: app:entity:id:field. It helps you group keys, find them with SCAN, and avoid collisions when several applications share one Redis.

📖 Answer

Examples:

shop:product:42
shop:cart:user:7
auth:otp:998901234567
stats:views:2026-11-03

A few rules:

  • the first part is the application or service name, especially when one Redis serves several services;
  • keep keys short: with a million keys, every extra byte costs RAM;
  • don't put variable stuff in a key (full JSON, long query text); take a hash of it if you need to;
  • if the cached format changes, add a version: shop:product:v2:42. That way the old format and the new code don't clash during a deploy.

Spring Cache builds keys in the form cacheName::key itself; with RedisCacheConfiguration.prefixCacheNameWith("shop:") you can put an application prefix in front.