K/V Store Resource
The Key/Value Store Resource is a batteries-included, minimalist persistence layer for your app.
The store is a fully-managed, linearly scalable key-value storage system running on a distributed database. Keys must be strings, but values can be any JSON content.
Programmatic Access
Programmatic access to the key/value store is available in server-side runtimes, such as the TypeScript Server Resource (opens in a new tab).
Example: TypeScript Server
await kv.set('example-key', { 'example value': 123 })
await kv.get('example-key') // => returns { "example value": 123 }
await kv.delete('example-key')
Properties
Keyspace
Prop | keyspace |
---|---|
Type | string |
Default | default |
The K/V store keyspace to use for all functions on this node. Specifying a keyspace introduces a prefix to all keys.
Actions
Get Key/Value Record
Gets a single record in the key/value store by key.
Parameter | Type | Default |
---|---|---|
key | string | undefined |
Set Key/Value Record
Sets a single key/value record specified by key.
Parameter | Type | Default |
---|---|---|
key | string | undefined |
value | unknown | undefined |
List Records
Lists all key/value records.
Parameter | Type | Default |
---|---|---|
pattern | string | undefined |
List Keys
Lists all keys in the specified range.
Parameter | Type | Default |
---|---|---|
pattern | string | undefined |
Delete Record
Deletes a single key/value record by key.
Parameter | Type | Default |
---|---|---|
key | string | undefined |
Increment Key
Increments a numeric field on a specific key/value record.
Parameter | Type | Default |
---|---|---|
key | string | undefined |
amount | number | 1 |
Decrement Key
Decrements a numeric field on a specific key/value record.
Parameter | Type | Default |
---|---|---|
key | string | undefined |
amount | number | 1 |