v0.7.0

Storage

Last updated


HakoRun switches between ToriiDB and Redis with a build tag; both share one key layout and version semantics.

Choosing a Backend


BackendBuildLocationNotes
ToriiDBmake build (default)~/.config/pardnchiu/hakorunEmbedded store, no extra service
Redismake build redis (-tags redis)REDIS_DB on REDIS_HOST:REDIS_PORTA failed PING at startup exits the process

Both implement one interface (internal/database/database.go):
  1. type backend interface {
  2. Add(ctx context.Context, script Script) (int64, error)
  3. Get(ctx context.Context, path string, version int64) (*Script, error)
  4. Close() error
  5. }

Key Layout


hash is the hex string of md5(path).
KeyToriiDBRedis
meta:<hash>JSON: path, language, latest, versionsHash: path, language, latest
code:<hash>:<timestamp>Source stringSource string
Version listversions array inside metaSet meta:<hash>:version

Writes and Reads


OperationBehavior
AddToriiDB writes code before meta, so meta never points at a missing version; Redis sends both in one pipeline
Get (version = 0)Reads latest from meta, then fetches that code
Get (pinned)Fetches code:<hash>:<version> directly; missing returns assign version not found
No metaReturns script not found, which the handler turns into HTTP 404

Handlers apply a 5-second timeout to storage calls.

中文