NuxtHub Key Value Storage automatically configures Nitro Storage, which is built on unstorage.
Enable the key-value storage in your NuxtHub project by adding the kv property to the hub object in your nuxt.config.ts file.
export default defineNuxtConfig({
hub: {
kv: true
}
})
When building the Nuxt app, NuxtHub automatically configures the key-value storage driver on many providers.
@upstash/redis packagepnpm add @upstash/redis
yarn add @upstash/redis
npm install @upstash/redis
bun add @upstash/redis
deno add npm:@upstash/redis
npx nypm add @upstash/redis
UPSTASH_REDIS_REST_URL environment variable to your Upstash Redis REST URL.UPSTASH_REDIS_REST_URL=https://...
UPSTASH_REDIS_REST_TOKEN=...
KV_REST_API_URL and KV_REST_API_TOKEN environment variables are set, and use them to configure the Upstash Redis connection.ioredis packagepnpm add ioredis
yarn add ioredis
npm install ioredis
bun add ioredis
deno add npm:ioredis
npx nypm add ioredis
REDIS_URL environment variable to your Redis connection URL.REDIS_URL=redis://localhost:6379
REDIS_URL or KV_URL environment variable are set, and use one of them to configure the Redis connection.When deploying to Cloudflare, it automatically configures Cloudflare Workers KV.
Add a KV binding to a Cloudflare Workers KV namespace in your wrangler.jsonc config.
{
"$schema": "node_modules/wrangler/config-schema.json",
// ...
"kv_namespaces": [
{
"binding": "KV",
"id": "<id>"
}
]
}
Learn more about adding bindings on Cloudflare's documentation.
When deploying to other providers, Nitro Storage kv is configured to use the filesystem.
Or directly set the REDIS_URL environment variable.
REDIS_URL=redis://localhost:6379
.data/kv.You can use any unstorage driver by configuring the hub.kv option with a driver and its options.
export default defineNuxtConfig({
hub: {
kv: {
driver: 'redis',
url: 'redis://localhost:6379',
/* any additional driver options */
}
}
})
CLI
Manage your Nuxt SQL database with the `npx nuxt db` CLI, including generating migrations, applying them, running SQL queries, and marking migrations as applied.
Usage
Learn how to store, retrieve, update, and delete key-value pairs in your Nuxt application, with practical examples and best practices.