v0.7.0

Value Types and Set Semantics

Last updated


This page explains how ToriiDB detects the type of a stored value and what SetDefault, SetNX, and SetXX do on write.

Value Types


Type is detected from the raw string on every write, in this order:
OrderTypeRuleString()
1TypeJSONValid JSON whose trimmed text starts with {/[ and ends with }/]json
2TypeIntstrconv.ParseInt(value, 10, 64) succeedsint
3TypeFloatstrconv.ParseFloat(value, 64) succeedsfloat
4TypeBoolexactly true or falsebool
5TypeDateRFC 3339 or 2006-01-02date
6TypeStringanything elsestring

"007" is detected as int even though it is not a valid JSON number; the daemon therefore re-checks json.Valid before sending such values as raw JSON.

Set Semantics


FlagBehavior
SetDefaultUpsert
SetNXFails with key already exists when the key is present
SetXXFails with key not found when the key is absent

Overwriting a key replaces its value, type, and ExpireAt, sets UpdatedAt, and clears Vector, because an old embedding no longer describes the new text. expireAt is an absolute Unix timestamp; the REPL converts a trailing <seconds> to one.

中文