Recommendation
Profile cache: use a Hash per user. Leaderboard: use a Sorted Set per board.
User profile: Hash
The JSON string forces fetch, parse, mutate and rewrite for every change. A Hash lets you touch one field at a time:
HSET user:1001:profile name "Ada" email "[email protected]" level 42 country "DE"
HSET user:1001:profile email "[email protected]" # update one field, no read needed
HGET user:1001:profile email # read one field
HGETALL user:1001:profile # read everything
HINCRBY user:1001:profile level 1 # atomic numeric update
EXPIRE user:1001:profile 3600 # TTL, since this is a cache
This is atomic, needs no read-modify-write cycle, and avoids lost updates when two writers race. It also sends far less data over the wire.
Hashes hold flat field/value pairs. If the profile has nested data, such as arrays of items or sub-objects, use the JSON type (JSON.SET user:1001:profile $.address.city '"Berlin"'). Otherwise a Hash is simpler and lighter. You can also keep rarely changed nested parts in a separate key, for example user:1001:settings.
Leaderboard: Sorted Set
ZADD game:space-invaders:leaderboard 12500 user:1001 # set/update score
ZINCRBY game:space-invaders:leaderboard 300 user:1001 # add points atomically
ZREVRANGE game:space-invaders:leaderboard 0 9 WITHSCORES # top 10
ZREVRANK game:space-invaders:leaderboard user:1001 # a player's rank
The member should be the user ID, not the whole profile. To render the board, take the top N IDs and fetch each profile with HMGET or HGETALL, pipelined.
Key naming
Use lowercase, colon-separated keys in the form {entity}:{id}:{attribute}. User_1001_Profile breaks that convention in casing, separators and order.
| Purpose | Key |
|---|---|
| Profile | user:1001:profile |
| Settings | user:1001:settings |
| Global leaderboard | game:space-invaders:leaderboard |
| Periodic board | game:space-invaders:leaderboard:2026-w43 |
| Session | session:abc123 |
Further tips:
- Keep keys short, because they live in memory and appear in every command.
- Pick one convention and apply it everywhere.
- If you're multi-tenant, prefix with the tenant (
tenant:42:user:1001:profile). That makes scans and ACLs easy to scope. - Time-bucketed leaderboard keys such as weekly or daily boards can be expired or rotated with
EXPIRE.
Migration
- Write a one-off script that reads each
User_*_Profilestring, parses it and doesHSET user:{id}:profile .... - Have the app write to the new keys, or dual-write briefly.
- Delete the old keys once reads are fully switched over. Use
SCANfor this, neverKEYS.
I can sketch the migration script or the client code in Python or Java if that would help.
Pure-instruction skill, so the trial gave the model only the Skill and Read tools: no network, no shell, no Redis server. The request mixes a data-model question with a key-renaming question.
它做什么
让模型按 Redis 官方的建议设计数据:数据类型要匹配访问方式,key 用短小、小写、冒号分隔的写法,例如 user:1001:profile。
工作方式
- 用一张决策表,把计数器、对象、队列、去重集合、排行榜、嵌套数据、事件日志、向量等场景对应到具体的 Redis 类型。
- 指出“把平铺对象序列化成一个字符串”这个常见反模式,并给出用 Hash 的写法(Python redis-py 和 Java Jedis)。
- 给出 key 命名规则:
{实体}:{id}:{属性},不用空格和大小写混用,不拿完整 URL 当 key,多租户加租户前缀。
适合
设计 Redis 数据模型、缓存对象或会话、做计数器和排行榜、整理混乱的 key 命名。
局限
这是个很短的 Skill(含两份参考文件约 7 KB),只讲数据类型和 key 命名,不涉及集群、持久化、搜索。
低风险:纯指令文件,来自 Redis 官方仓库(MIT 协议)。没有脚本、不联网、不写文件,也不需要账号或密钥。它只给建议,不会连接你的 Redis。迁移相关的建议请先对照自己的数据再执行。