• Projects
  • Service
  • About
  • branding.bz
  • Podcast
  • Tips
  • FAQ
  • Recruit
  • Download
  • Contact
  • branding.bz(ブランド構築SaaS)
  • DESIGN NOW(デザインメディア)
  • X
  • LinkedIn
  • Spotify
  • Facebook

213-0011 神奈川県川崎市高津区久本3-6-7-303

© 2026 ID INC. All rights reserved

claude-skills/スキル
SKILLOfficialdatabase

redis-core

プラグイン
redis-development
ライセンス
MIT
ソース
GitHub で見る ↗
説明

Redis(高速データベース)のモデル設計に関する基本的なガイダンス — 適切なデータ構造(文字列、ハッシュ、リスト、セット、ソート済みセット、JSON、ストリーム、ベクトルセット)を選択し、コロン区切りの一貫性のあるキー名を使用する。 **次のような場合に使用:** - Redis のデータモデルを設計するとき - オブジェクトをキャッシュ(一時保存)するとき - ハッシュと JSON のどちらを使うかを判断するとき - カウンターを構築するとき - ランキング機能を作成するとき - メンバーシップセット(グループ管理用の集合)を管理するとき - セッションストア(ユーザーの一時情報の保存場所)を構築するとき - Redis のキー名を見直したり整理したりするとき

原文を表示

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.

ユースケース
  • Redisのデータモデルを設計するとき
  • オブジェクトをキャッシュするとき
  • ハッシュとJSONの使い分けを判断するとき
  • カウンターを構築するとき
  • ランキング機能を作成するとき
本文(日本語訳)

Redis Core

Redisでデータをモデル化するための基本的なガイダンスです。データ型の選択とキー名の命名規則の2つの決定について説明しており、この2つがメモリ使用量、処理速度、保守性に最も直接的な影響を与えます。

次のような場合に使用します

  • オブジェクト、セッション、ユーザー単位の状態をキャッシュする場合
  • カウンター、ランキング、最新アイテムのリスト、ユニークな会員セットを扱う場合
  • Redisのキー名を確認または改善したい場合
  • あるエンティティに対して、Redisのハッシュ(複数フィールドのデータ型)とJSONドキュメントのどちらを使うかを決める場合

1. 適切なデータ構造を選択する

データの形だけでなく、実際のアクセス方法に合ったデータ型を選んでください。

用途 推奨型 理由
シンプルな値、カウンター String(文字列) INCR/DECR、SET/GETが原子的(確実に完了)
フィールドを個別に更新するオブジェクト Hash(ハッシュ) フィールド単位での読み書きが可能、全体の書き直し不要
キュー、最新N件のアイテム List(リスト) 先頭と末尾への追加・削除が高速(O(1))
ユニークなアイテム、メンバーシップ確認 Set(集合) 追加・確認・個数カウントが高速(O(1))
ランキング、スコアに基づく範囲検索 Sorted Set(スコア付き集合) スコア順に整列、スコアに基づく検索が可能
ネストされた・階層的なデータ JSON 経路単位での更新、ネストした配列、インデックス機能
イベントログ、ファンアウト(複数への一括配信) Stream(ストリーム) 永続化、コンシューマーグループ対応
ベクトル類似度検索 Vector Set(ベクトル集合) ネイティブなベクトル保存、高速近傍探索

よくある落とし穴: フラットなオブジェクトを文字列にシリアライズして保存することです。1つのフィールドを更新するたびに、取得→解析→変更→保存という4つのステップが必要になります。代わりにハッシュを使いましょう。

詳しい説明とPython/Javaの例についてはreferences/choose-data-structure.mdを参照してください。

2. 一貫性のあるキー名を使う

コロン区切りのセグメントで安定した階層構造を作ります:

{エンティティ}:{ID}:{属性}
user:1001:profile
user:1001:settings
order:2024:items
session:abc123
article:987:likes
game:space-invaders:leaderboard

ポイント:

  • 小文字、コロン区切り。 スペースや大文字混在(User_1001_Profileなど)は避けてください。
  • 短くて読みやすいキーを心がける — キーはメモリに保存され、すべてのコマンドに含まれます。
  • フルURLや長い文字列をキーにしない。 短い識別子を抽出するか、URLのハッシュ値を使ってください。
  • マルチテナント対応の場合は接頭辞をつける (tenant:42:user:7:cartなど)。これにより、スキャンやアクセス制御をテナント単位で制御できます。
  • 一貫性を保つ。 サービスごとに1つの命名規則を決めて、すべてのキーに適用してください。

クリーンアップ例とエッジケースについてはreferences/key-naming.mdを参照してください。

参考資料

  • Redis: データ型の選択
  • Redis: キー
原文(English)を表示

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 case Recommended type Why
Simple values, counters String Atomic INCR/DECR, SET/GET
Object with independently updated fields Hash Per-field reads/writes, no whole-object rewrite
Queue, recent-N items List O(1) push/pop at ends
Unique items, membership checks Set O(1) SADD/SISMEMBER/SCARD
Rankings, score-based ranges Sorted Set Score-ordered; ZADD/ZRANGE/ZRANK
Nested / hierarchical data JSON Path-level updates, nested arrays, RQE indexing
Event log, fan-out messaging Stream Persistent, consumer groups
Vector similarity Vector Set Native 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 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:profile
user:1001:settings
order:2024:items
session:abc123
article:987:likes
game: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 for cleanup examples and edge cases.

References

  • Redis: Choosing the right data type
  • Redis: Keys

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。