Skip to content

feat(kv): add atomic operations - #927

Open
onmax wants to merge 4 commits into
nuxt-hub:mainfrom
onmax:feat/atomic-kv
Open

feat(kv): add atomic operations#927
onmax wants to merge 4 commits into
nuxt-hub:mainfrom
onmax:feat/atomic-kv

Conversation

@onmax

@onmax onmax commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

NuxtHub KV users on Redis and Upstash can now atomically read and delete a value or increment an expiring counter. Each operation takes one server request and prevents another request from changing the value between the read and write.

This also gives @nuxtjs/better-auth the NuxtHub KV operations it needs for Better Auth 1.7 secondary storage when users configure Redis or Upstash. Without getAndDelete() and increment(), affected users need a separate storage adapter. The limitation was reported in nuxt-modules/better-auth#423.

Driver behavior

Driver Behavior Provider reference
Redis Both methods are available Redis Lua scripting
Upstash Both methods are available Upstash GETDEL · Upstash EVAL
Deno KV Both methods are unavailable Deno KV transactions · Deno KV key expiration
Cloudflare KV Both methods are unavailable How Workers KV works
S3 Both methods are unavailable No matching operation in the NuxtHub driver
fs-lite Both methods are unavailable No matching operation in the local driver

Redis runs both methods in Lua scripts. This keeps getAndDelete() compatible with Redis versions before GETDEL and lets increment() check whether the key existed before setting its expiry. Upstash uses its native GETDEL command and a Lua script for the counter.

Deno KV can make the update atomic, but it cannot preserve the counter's original fixed expiry when writing the next value through this interface. The unsupported drivers therefore do not advertise these methods or fake them with separate get(), delete(), and set() calls.

Atomic reads use the same destr decoder as ordinary KV reads, preserving long numeric strings and matching literal and prototype-key handling. The generated KV package imports the helper from @nuxthub/core/kv/atomic, so destr resolves from its owning runtime package rather than the consuming app.

Before · After. The repository reproduction covers both command response shapes; it does not exercise live Redis or Upstash servers.

@vercel

vercel Bot commented Aug 30, 2026

Copy link
Copy Markdown

@onmax is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Aug 30, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxthub/core@927

commit: 43967ac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant