Redis Core

作者 redisa84871d065f3MIT收錄於 2026年10月8日更新於 2026年10月8日

Core Redis modeling guidance — choose the right data structure (String, Hash, List, Set, Sorted Set, JSON, Stream, Vector Set) and use consistent colon-separated key names. Use when designing a Redis data model, caching objects, deciding between Hash and JSON, building counters, leaderboards, membership sets, or session stores, or when reviewing/cleaning up Redis key naming.

AI 產生的概覽

提供 Redis 資料建模指引:選擇合適的資料結構,並使用一致的冒號分隔鍵名。

功能
此技能提供 Redis 資料建模的基礎指引,涵蓋兩項決策:該用哪種資料型別(String、Hash、List、Set、Sorted Set、JSON、Stream、Vector Set),以及如何命名鍵。內容包含使用情境與型別對照表、鍵命名規則,以及兩份提供完整理由、範例和清理邊界情況的參考文件。它產出的是建議與慣例,而非程式碼或檔案。
適用情境
適用於設計 Redis 資料模型、快取物件或工作階段、建立計數器、排行榜、成員集合,或在 Hash 與 JSON 文件之間做選擇時。也適用於檢視或重構現有的 Redis 鍵名。
執行需求
不需要指令碼或工具,僅包含說明和兩份參考文件。只有在開啟其引用的外部 Redis 文件連結時才需要網路存取。

Redis Core

Foundational guidance for modeling data in Redis. Covers data-type selection and key-name conventions — the two decisions that most directly drive memory, performance, and maintainability.

When to apply

  • Caching objects, sessions, or per-user state.
  • Counters, leaderboards, recent-items lists, unique-membership sets.
  • Reviewing or refactoring Redis key names.
  • Deciding between a Redis Hash and a JSON document for an entity.

1. Choose the right data structure

Pick the type that matches the access pattern, not just the shape of the data.

Use caseRecommended typeWhy
Simple values, countersStringAtomic INCR/DECR, SET/GET
Object with independently updated fieldsHashPer-field reads/writes, no whole-object rewrite
Queue, recent-N itemsListO(1) push/pop at ends
Unique items, membership checksSetO(1) SADD/SISMEMBER/SCARD
Rankings, score-based rangesSorted SetScore-ordered; ZADD/ZRANGE/ZRANK
Nested / hierarchical dataJSONPath-level updates, nested arrays, RQE indexing
Event log, fan-out messagingStreamPersistent, consumer groups
Vector similarityVector SetNative vector storage with HNSW

Common anti-pattern: stuffing a flat object into a serialized string. Updating one field means fetch + parse + mutate + rewrite. Use a Hash instead.

See references/choose-data-structure.md [blocked] for full rationale and Python/Java examples.

2. Use consistent key names

Use colon-separated segments with a stable hierarchy:

{entity}:{id}:{attribute}user:1001:profileuser:1001:settingsorder:2024:itemssession:abc123article:987:likesgame:space-invaders:leaderboard

Rules of thumb:

  • Lowercase, colon-separated. No spaces, no mixed casing (User_1001_Profile is bad).
  • Keep keys short but readable — keys live in memory and appear in every command.
  • Don't use full URLs or long strings as keys. Extract a short identifier, or use a hash digest of the URL.
  • Prefix for multi-tenancy (tenant:42:user:7:cart) so scans and ACLs can target a tenant cleanly.
  • Be consistent. Pick one convention per service and apply it across all keys.

See references/key-naming.md [blocked] for cleanup examples and edge cases.

References

來源與署名

來源:redis/agent-skills位於plugins/redis-development/skills/redis-core提交a84871d

授權條款: MIT

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架