Files
life-echo/api/.agents/skills/redis-development/rules/data-key-naming.md
Sully 53e0065e3e refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)
配置 SSOT(TOML + .env)
统一错误契约
Auth 与事务边界
Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client
可观测性(OpenTelemetry + LGTM)
2026-05-22 13:44:50 +08:00

1.7 KiB

title, impact, impactDescription, tags, description, alwaysApply
title impact impactDescription tags description alwaysApply
Use Consistent Key Naming Conventions MEDIUM Improved maintainability and debugging keys, naming, conventions, prefixes Use Consistent Key Naming Conventions true

Use Consistent Key Naming Conventions

Well-structured key names improve code maintainability, debugging, and enable efficient key scanning.

Correct: Use colons as separators with a consistent hierarchy.

# Pattern: service:entity:id:attribute
user:1001:profile
user:1001:settings
order:2024:items
cache:api:users:list
session:abc123

Python (redis-py):

# Good: Short, meaningful key
redis.set("product:8361", cached_html)
page = redis.get("product:8361")

Java (Jedis):

// Good: Short, meaningful key derived from URL
jedis.set("product:8361", "<some cached HTML>");
String page = jedis.get("product:8361");

Incorrect: Inconsistent naming, spaces, or very long keys.

# These cause confusion and waste memory
User_1001_Profile
my key with spaces
com.mycompany.myapp.production.users.profile.data.1001

Java (Jedis):

// Bad: Using full URL as key wastes memory and slows comparisons
jedis.set("http://www.verylongurlkey.com/store/products/product.html?id=8361",
          "<some cached HTML>");

Key naming tips:

  • Keep keys short but readable—they consume memory
  • Consider key prefixes for multi-tenant applications
  • Extract short identifiers from URLs or long strings rather than using the whole thing
  • For large binary values, consider using a hash digest as the key instead of the value itself
  • Use consistent separators (colons are conventional)

Reference: Redis Keys