数据存储规范
This skill is the storage contract between market-data producers and index-api. Use it to design or review Redis Cluster / RedisJSON / RediSearch keys, StarRocks tables, and producer-consumer behavior.
Load Only What You Need
- Redis key, RedisJSON, RediSearch, TTL, relation cache:
references/redis-spec.md - StarRocks table, primary key, partition, bucket, period strategy:
references/starrocks-spec.md - Existing Redis namespaces that new business may need to reuse:
references/existing-redis-keys.md - Quick naming examples only:
references/naming-cheatsheet.md - Full examples:
examples/redis-snap-base.md,examples/relation-redis.md,examples/bar_security_quote_1m.sql
Do not duplicate detailed rules in answers from memory. Load the relevant reference when the task asks for an actual key, JSON shape, table name, DDL, or review.
Routing
| Data type | Primary store | Rule |
|---|---|---|
| Current snapshot/event | Redis Cluster | Sync to StarRocks on schedule when history is needed |
| Pure historical K-line/bar | StarRocks | Skip Redis unless a hot cache is explicitly needed |
| Relation/group/holding/component | StarRocks source of truth + Redis hot cache | Phase 1 Redis-only is acceptable when explicitly scoped |
Design Order
- Decide store: Redis, StarRocks, or StarRocks + Redis cache.
- Decide entity type:
security,env, orentity. - Check
references/existing-redis-keys.mdbefore proposing any new Redis namespace or StarRocks table. - Decide flat vs attributed:
- Flat no-attribute profile data, such as company name, institution name, listing date, fund official URL, does not get a default period/phase in Redis.
- Non-flat or attributed data defaults to
1dayin Redis and StarRocks unless the indicator itself already carries a period, such as 20-day return.
- Put Redis attributes in this order: period, trading phase, other attributes.
- Reuse same-business storage when period, entity type, update cadence, query contract, and performance boundary match.
- New Redis namespace or StarRocks table requires a concrete mismatch reason.
Hard Rules
symbolis alwaysmarket:codefor securities, e.g.185:AAPL.- Redis entity ids must use hash tags:
{185:AAPL}or{entity_id}. - RedisJSON is the default; Hash/Zset require a concrete access-pattern reason.
- RediSearch index prefix equals the Redis key prefix without
{entity}. - Continuous multi-period history stores only
1min,5min,60min,1day; derived periods are merged byindex-api. - Sparse discrete period attributes may use dedicated periods such as
240min,1month,1year. - StarRocks same-business additions add columns; RedisJSON same-business additions add indicator key/value.
- Missing values are
NULL/ JSON null, never fake values like0,-1, or"". - Batch producers write completion heartbeat:
production:status:<task_id>:<trade_date>. - StarRocks default replica count is
2.
Naming
Redis key:
[数据分类]:[业务分类](:[属性...]):{实体id}
Examples:
snap:crypto_f10:{market:ticker}
snap:option_rating:1day:{market:ticker}
snap:base:1day:pre:{185:AAPL}
relation:group:<group_id>
StarRocks table:
[表类型]_[指标类型]_[业务名称]_[周期]
Example:
bar_security_option_greeks_1day
Reject
snap:<business>:pre:1day:{entity}: wrong order; usesnap:<business>:1day:pre:{entity}.snap:<business>:1day:{entity}for flat no-attribute profile data: omit the period.- New namespace/table for a field that fits
references/existing-redis-keys.md. - New namespace/table for a same-business indicator when adding a RedisJSON key/value or StarRocks column is enough.
- Extra dimensions such as source, scenario, language, region, or version before they are query/filter/routing dimensions or real performance boundaries.
