配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
1.4 KiB
1.4 KiB
title, impact, impactDescription, tags, description, alwaysApply
| title | impact | impactDescription | tags | description | alwaysApply |
|---|---|---|---|---|---|
| Use JSON Paths for Partial Updates | MEDIUM | Avoids fetching and rewriting entire documents | json, partial-updates, paths, atomic | Use JSON Paths for Partial Updates | true |
Use JSON Paths for Partial Updates
Use JSON path syntax to update specific fields without fetching the entire document.
Correct: Use JSON paths for targeted updates.
# Store JSON document
redis.json().set("user:1001", "$", {
"name": "Alice",
"email": "alice@example.com",
"preferences": {"theme": "dark", "notifications": True}
})
# Update nested field without fetching entire document
redis.json().set("user:1001", "$.preferences.theme", "light")
# Get specific field
theme = redis.json().get("user:1001", "$.preferences.theme")
# Increment numeric field atomically
redis.json().numincrby("user:1001", "$.preferences.volume", 5)
# Append to array
redis.json().arrappend("user:1001", "$.tags", "premium")
Incorrect: Storing JSON as a string and parsing client-side.
# Bad: Loses queryability and atomic updates
redis.set("user:1001", json.dumps(user_data))
# Must fetch, parse, modify, serialize, and rewrite
data = json.loads(redis.get("user:1001"))
data["preferences"]["theme"] = "light"
redis.set("user:1001", json.dumps(data))
Reference: Redis JSON Path