Storage on Every Host
wisp::kv, wisp::blobs and wisp::sql are one API on every Wisp host. One environment variable per store picks where the data goes.
let kv = wisp::kv("SESSIONS");
kv.put_for(&format!("sess:{id}"), &user, 30 * 86_400).await?; // TTL in seconds
let who: Option<String> = kv.get(&format!("sess:{id}")).await?;
let page = kv.list_page("sess:", "", 100).await?; // Page { keys, cursor }
let photos = wisp::blobs("PHOTOS");
photos.put("a.png", png, "image/png").await?;
let blob = photos.get("a.png").await?; // Blob { body, content_type }
let rows: Vec<Recipe> = wisp::sql("DB").all("select * from recipes where owner = ?", &[&id]).await?;
The full API (metadata, absolute expiry, get_json, put_json, list) is on Bindings.
A page can hold fewer than limit keys while more exist. Walk until the cursor is None. A page of an upstash store shows each name once. The same name may show on another page, because Redis SCAN may repeat a key. A list call of an fs store reads the folder once and keeps at most 1001 keys of the scan in memory.
Choosing a Driver
WISP_KV_<NAME> picks the driver of wisp::kv("NAME"), WISP_BLOB_<NAME> of wisp::blobs("NAME") and WISP_SQL_<NAME> of wisp::sql("NAME"). Nothing is opened until the first call, and an app that uses none carries none of the code. Wisp keeps the driver of each store name until the process stops, so name the stores in the code, not from request data.
WISP_KV_* / WISP_BLOB_* / WISP_SQL_* | kv | blobs | sql | Runs on |
|---|---|---|---|---|
cf:BINDING | Workers KV | R2 | D1 | Cloudflare Workers and Pages |
deno-kv, deno-kv:<path or url> | yes | yes, 64 KiB each | Deno, Deno Deploy | |
netlify-blobs, netlify-blobs:<store> | yes | yes | Netlify Functions and Edge Functions | |
fs, fs:<dir> | yes | yes | the built-in server, wisp dev, containers | |
memory | yes | yes | the built-in server (gone on restart) | |
upstash, upstash:<url> | Redis over REST | every host | ||
s3:<endpoint>/<bucket> | yes | every host | ||
vercel-blob, vercel-blob:private | yes | every host | ||
libsql://<host>, https://<host>, http://<host> | yes | every host | ||
d1-http:<account id>/<database id> | yes | every host |
With fs, one server process owns a data folder. Its first store call locks .wisp-store.lock in the folder until the process stops. A second process on the folder waits for WISP_STOP_DELAY + WISP_DRAIN + 5 seconds. Then its store call fails with a 503: fs:<dir>: another process uses it. The other calls on the folder wait with that call and get its result. After a failed wait, each store call on the folder fails at once with the same 503 for the same time. Then the next call waits again. A store call on another folder does not wait. On NFS or SMB, the lock may not hold.
An expired key reads as missing and is not listed. The get or list that finds it expired deletes its file, so the folder does not grow with expired keys. A put of the same key at that time keeps its file. When the file locks of the file system do not work, Wisp writes one log line and keeps the files of expired keys.
The last five drivers speak HTTP: the host's fetch on the edge, wisp::fetch on the built-in server. There an https store needs Wisp's tls feature (wisp = { features = ["tls"] }, off by default) or the first call answers a 500 naming it. wisp::fetch opens a connection per call, so keep hot keys in fs or memory. A store sends its token over https only. Plain http is for localhost, 127.0.0.1 and [::1], else the first call answers a 500: a token goes over https only (plain http is for localhost). This holds for upstash, vercel-blob, libSQL with a token, and s3: with a session token. Plain http to an s3: host that is not this machine sends the request bodies and the signatures in clear text. Use https.
Defaults per Host
| Host | Unset WISP_KV_* / WISP_BLOB_* | Unset WISP_SQL_* |
|---|---|---|
| Cloudflare | the binding called NAME in wrangler.toml | the D1 binding NAME |
| Deno Deploy | Deno KV (when there is no binding NAME) | 501 |
| Netlify | Netlify Blobs, store NAME | 501 |
| Vercel | none: set upstash (Vercel KV, Marketplace Redis) and vercel-blob | 501 |
| Node, Bun, Azure (Node build) | none: set upstash or s3: | 501 |
| AWS Lambda | fs under /tmp/wisp-data/storage, per instance: set upstash or s3: | 501 |
VPS, Docker, Fly, Railway, Render, Cloud Run, wisp dev | fs: $WISP_DATA/storage when WISP_DATA is set (memory when off), else .wisp/data | 501 |
A store with no driver answers a 500 on the first call naming the variable to set. It never panics. The message shows only the scheme and the host of the value, such as WISP_KV_X is redis://h.example:6379. A value with no :// shows only its driver word (fs, cf), else (hidden).
Settings of Each Driver
upstash: URL fromUPSTASH_REDIS_REST_URL(orKV_REST_API_URL) unless the spec has one. Token fromWISP_KV_<NAME>_TOKEN,UPSTASH_REDIS_REST_TOKENorKV_REST_API_TOKEN. Keys are prefixed<length of NAME>:NAME:, so stores share a database without meeting. Metadata sits beside the key and no list shows it. A non-UTF-8 value is kept as\0wisp-b64:and its base64.s3:<endpoint>/<bucket>: path-style, AWS Signature Version 4. Key fromWISP_BLOB_<NAME>_KEY_ID(orAWS_ACCESS_KEY_ID) andWISP_BLOB_<NAME>_SECRET(orAWS_SECRET_ACCESS_KEY), optionalWISP_BLOB_<NAME>_SESSION_TOKEN(orAWS_SESSION_TOKEN). Region fromWISP_BLOB_<NAME>_REGIONorAWS_REGION, else the endpoint:autofor R2, the region ofs3.<region>.amazonaws.com, elseus-east-1(MinIO). Examples:s3:https://s3.eu-west-2.amazonaws.com/photos,s3:https://<account>.r2.cloudflarestorage.com/photos,s3:http://localhost:9000/photos.vercel-blob: token fromWISP_BLOB_<NAME>_TOKENorBLOB_READ_WRITE_TOKEN(it names the store). A put overwrites in place, and a public store's CDN may serve the old blob for up to 60 s. Add:privatefor a private store, whose reads carry the token.VERCEL_BLOB_API_URLmoves the API.libsql://<host>: Turso or any libSQL server, over its HTTP pipeline. Token fromWISP_SQL_<NAME>_TOKEN, sent overhttpsonly (a plainhttp://address with a token is refused unlesslocalhost,127.0.0.1or[::1]). A BLOB column reads as base64 text. An integer argument outside the 64-bit range of libSQL is a 500 that names it, so Wisp loses no digits. The 500 shows the first 20 characters of a longer value.d1-http:<account>/<database>: D1 from outside Cloudflare, over its REST API. Token (with D1 edit) fromWISP_SQL_<NAME>_TOKENorCLOUDFLARE_API_TOKEN. Each id holds only letters, digits,-and_, so an id cannot change the path of the API. Else each call fails with a 500. It names which id (account or database) and its first refused character, never the rest of the id or the token:WISP_SQL_DB is d1-http: it is d1-http:<account id>/<database id>, and each id holds only letters, digits, - and _ (the account id has "?" at byte 1). An empty id gets(the database id is empty)or(the account id is empty).deno-kv: keys are[kind, NAME, key]in the databaseDeno.openKvopens. Local Deno needs--unstable-kv.netlify-blobs: the site storeNAME(or the one the spec names), reached with theNETLIFY_BLOBS_CONTEXTNetlify gives each function.fs:<dir>: one file per key under<dir>/<kv or blob>/<name>/, with escaped names so no key leaves the folder. A put writes a temporary file and renames, so a reader never sees half a value.
What Each Driver Keeps
- Expiry (
put_for,KvPut { ttl, expires }) holds on every driver. Cloudflare needs at least 60 s. - Lists come in key order.
upstash,netlify-blobs,s3:andvercel-bloblist names only, with no expiry or metadata. Netlify Blobs takes no page size. A Netlify Blobs key with a.or..segment is an error. - An
s3:orvercel-blobkey that is empty or has a.or..segment gets a 400. A list's prefix may be empty. - On every store, an empty metadata or content type reads back as
None. - A Deno KV value is at most 64 KiB (65,536 bytes, with its metadata and type): a larger put answers 413. Keep larger blobs in
s3:orvercel-blob.
Host Bindings Stay on Their Host
wisp::platform::call(binding, method, ...) reaches a Cloudflare binding (Workers AI, Queues, Durable Objects) and runs only there. Elsewhere it answers 501. Use the binding's HTTP API through wisp::fetch for code that must run off Cloudflare.
Is This Page Useful?