Key-Value Store

Eric AllamEric Allam

Image forKey-Value Store

The Key-Value Store enables you to store and retrieve small chunks of serializable data in and outside of your Jobs.

Use the io.store object to access namespaced stores inside of your Run functions. Or use client.store to access the environment store anywhere in your app!

Sharing data across Runs with io.store.job:


_13
client.defineJob({
_13
...
_13
run: async (payload, io, ctx) => {
_13
// this will only be undefined on the first run
_13
const counter = await io.store.job.get<number>("job-get", "counter")
_13
_13
const currentCount = counter ?? 0
_13
const incrementedCounter = currentCount++
_13
_13
// Job-scoped set
_13
await io.store.job.set("job-set", "counter", incrementedCounter);
_13
}
_13
})

Sharing data across Jobs with io.store.env:


_20
client.defineJob({
_20
id: "job-1",
_20
...
_20
run: async (payload, io, ctx) => {
_20
// store data in one job
_20
await io.store.env.set("cacheKey", "cross-run-shared-key", { foo: "bar" });
_20
}
_20
})
_20
_20
client.defineJob({
_20
id: "job-2",
_20
...
_20
run: async (payload, io, ctx) => {
_20
// access from a different job
_20
const value = await io.store.env.get<{ foo: string }>("cacheKey", "cross-run-shared-key");
_20
}
_20
})
_20
_20
// or anywhere else in your app
_20
await client.store.env.get<{ foo: string }>("cross-run-shared-key");

Full docs for io.store and client.store.

,