Use when discussing 一致性哈希, virtual nodes, load balancing sticky keys, or comparing hash-mod vs consistent hash. Do not confuse with Redis Cluster hash slots (backend-redis-ops) or DB sharding keys (backend-sharding).
Scanned 9/3/2026
Install to Claude Code
npx -y skills add 1398281322-a11y/java-backend-guardrails --skill consistent-hash --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Consistent Hash?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/1398281322-a11y-consistent-hash)More formats (shields.io, HTML) on the badges page.
---
name: consistent-hash
description: Use when discussing 一致性哈希, virtual nodes, load balancing sticky keys, or comparing hash-mod vs consistent hash. Do not confuse with Redis Cluster hash slots (backend-redis-ops) or DB sharding keys (backend-sharding).
---
# 一致性哈希
## When to Invoke
缓存节点扩缩容、按 key 粘滞到实例、面试问「加机器要不要全量迁移」。
## When NOT
选 MySQL 分片键 → `sharding`。Redis Cluster 槽位 → `redis-ops`。两者都 **不是** 经典一致性哈希。
## 风险(面试考点)
普通 `hash(key) % N`:N 从 8 变 16,**几乎所有 key 换节点** → 缓存雪崩式回源。
一致性哈希:key 和节点都映射到环上,顺时针找最近节点。加一台只迁移邻居一段,约 `1/N`。
没有虚拟节点时,真实节点少会严重不均。生产用 **虚拟节点**(一台机器挂很多环上点)。
Redis Cluster:`CRC16(key) % 16384` 固定槽,槽再分配给节点。扩容是 **迁移槽**,算法不是一致性哈希。面试把两者说成一回事是错的。
## 方案选型(轻量优先)
| 问题 | 默认 |
|------|------|
| Redis 官方集群 | 槽位,不要自己造一致性哈希客户端(除非 Codis 老方案) |
| 本地缓存节点 / 某些负载 | 一致性哈希 + 虚拟节点 |
| DB 分片 | 取模或范围;扩容用双写/迁移,不靠环 |
## 默认方案
需要自研粘滞时:虚拟节点数足够(每物理节点数百)、哈希用稳定算法(如 Murmur)、节点摘除要摘它的全部虚节点。
哈希环不解决「节点内存大小不同」——用权重虚节点数量表达容量。
## 反例
错误:Redis Cluster 16384 槽 = 一致性哈希。
正确:固定槽表。
错误:DB `user_id % 8` 改 `% 16` 当一致性哈希无感扩容。
正确:取模扩容要迁移约一半或更多,必须有迁移方案。
## 验证
- 加 1 个缓存节点,回源只升高对应那一段 key,不是全量 miss。
- 节点分布用虚节点后标准差可接受。
## 评审清单
- [ ] 没把 Cluster 槽位说成一致性哈希
- [ ] 没把 DB 取模扩容说成无感
- [ ] 自研环有虚拟节点
---
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!
Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...
Ultra-compressed communication mode. Cuts token usage ~75% by speaking like caveman while keeping full technical accuracy. Supports intensity levels: lite, full (default), ultra, wenyan-lite, wenyan-full, wenyan-ultra. Use when user says "caveman mode", "talk like caveman", "use caveman", "less tokens", "be brief", or invokes /caveman. Also auto-triggers when token efficiency is requested.
Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.
**Complete production-ready guide for Google Gemini embeddings API** This skill provides comprehensive coverage of the `gemini-embedding-001` model for generating text embeddings, including SDK usage, REST API patterns, batch processing, RAG integration with Cloudflare Vectorize, and advanced use cases like semantic search and document clustering. ---
Recovers prior coding-agent session context by running `catchup <agent> --since-compact`, which extracts a clean summary of a previous Codex, Claude Code, Antigravity, OpenCode, or Pi Agent session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", or asks to recover/summarize a previous session before continuing. Do NOT use for the current conversation, git history, or any non-agent log.