360 Secure SkillHub
360 安全技能中心

Data Storage Spec

提供行情数据存储的设计契约:Redis Cluster/RedisJSON/RediSearch key 结构、StarRocks 表 DDL、分区与分桶、主键模型、周期策略、命名规则、TTL 与清理,以及生产者到 index-api 的约定,并给出可复用的既有 Redis 命名空间与命名速查示例。

jnlzw
jnlzw
热度 21.13
最近更新 2026-06-08 15:59:59
分类:数据依赖:纯提示词应用场景:数据处理 / 模板 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add data-storage-spec
Metadata
name
data-storage-spec
description
Use when designing, reviewing, or implementing financial market-data storage with Redis Cluster, RedisJSON, RediSearch, or StarRocks. Covers quotes, K-lines/bars, snapshots, events, options, fund holdings, index components, Redis key namespaces, JSON document shape, StarRocks DDL, partitioning, bucketing, primary key model, period strategy, multi-market data, relation/group/holding storage, table/key/field naming, TTL, cleanup, and producer-to-index-api contracts. Trigger on 行情, 快照, K线, bar, snap, event, StarRocks, Redis Cluster, RedisJSON, RediSearch, dynamic partition, primary key model, market:code symbols such as 185:AAPL, or 写作资料 / 数据存储规范. Do not use for unrelated Redis/StarRocks tutorials or general OLTP database design.

数据存储规范

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

  1. Decide store: Redis, StarRocks, or StarRocks + Redis cache.
  2. Decide entity type: security, env, or entity.
  3. Check references/existing-redis-keys.md before proposing any new Redis namespace or StarRocks table.
  4. 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 1day in Redis and StarRocks unless the indicator itself already carries a period, such as 20-day return.
  5. Put Redis attributes in this order: period, trading phase, other attributes.
  6. Reuse same-business storage when period, entity type, update cadence, query contract, and performance boundary match.
  7. New Redis namespace or StarRocks table requires a concrete mismatch reason.

Hard Rules

  • symbol is always market:code for 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 by index-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 like 0, -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; use snap:<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.