KV Store
Store values addressed by a key on Azion, create namespaces through the Azion API, and read and write keys from inside a function.
A key-value store holds each value under a name you choose, and finds it again by that name alone. There are no tables, no columns, and no query language: a read asks for one key and gets back what was last written to it. That narrow shape is what makes the lookup cheap, and it is also the trade, because nothing searches the values and nothing lists the keys for you.
KV Store runs that model on Azion’s distributed infrastructure. Keys live inside a namespace, which you create through the Azion API and address by its name. A function reads and writes those keys through Azion.KV, a global of Azion Runtime that needs no import and no credential. Use KV Store for the small values a request needs immediately: session state, feature flags, routing and redirect tables, per-user preferences, and rate-limit counters.
Keys and values
A function opens a namespace by name, then reads and writes keys on the client that open returns:
Azion.KV.openis the only way to obtain a client, and it is asynchronous. Every client names a namespace, because there is no default one.puttakes the key, the value, and an options object. A value is a string, an object, anArrayBuffer, aReadableStream, or a typed array view;metadatarides alongside it and comes back withgetWithMetadata.gettakes the key and the type you want back:text,json,arrayBuffer, orstream. Pass an array of keys instead of one, and it returns an object keyed by name.- A key that was never written returns
nullrather than throwing. The caller checks for it; it is not an error condition.
How a key reaches a function
A namespace is created once through the API. Everything after that happens inside a request:
- You create the namespace through the Azion API. It is synchronous, and there is no provisioning state to wait on.
- A request arrives for your application, and Rules Engine evaluates the rules of the current phase.
- A rule whose criteria match runs its behaviors, one of which selects a function instance.
- Azion Runtime executes that function’s handler.
Azion.KV.openresolves the namespace by name. A name no namespace on the account carries throwsNotFound.- The handler calls
put,get,getWithMetadata, ordelete, and returns its response.
Creating the namespace outside the request keeps the request path short, and it costs you the ability to provision one on demand: a function cannot create the namespace it needs, so the name has to exist before the code that opens it ships.
What KV Store covers
- Interfaces. Two. The Azion API creates, lists, and retrieves namespaces; the
Azion.KVclient reads and writes keys inside a function. Azion Console has no KV Store screen, and Azion CLI and the Azion Terraform provider carry no KV Store command or resource — there is nothing to look for in any of the three. - Availability. KV Store is a Preview product on every service plan. It is not enabled on an account by default, and access is requested through a support ticket. To request it, refer to Technical Support.
- Bounds. A namespace name is 3 to 63 characters of letters, numbers, the hyphen, and the underscore, and it is unique across the account. A namespace is permanent: it cannot be renamed, emptied, or deleted, so its name is worth settling before the first request. For every bound and the usage each plan includes, refer to KV Store limits.
- Consistency. A write is visible immediately where it lands and converges elsewhere afterwards, so a read can return the value a newer write replaced. How KV Store works covers what that changes about the code you write.
- Recommendations and failures. Best practices covers naming a namespace you cannot rename, deriving key names when nothing lists them, and reading both of the error shapes the platform returns. When a call throws, a build fails on an
azion:kvimport copied from older material, or a namespace the API lists is not found from a function, refer to Troubleshooting. - What it does not do. There is no key listing, no atomic increment, and no operation that spans more than one key as a unit. KV Store holds small values addressed by name, so unstructured files belong in Object Storage, relational records in SQL Database, and a response you want served again in Cache.