Registry / database / keyv-upstash

keyv-upstash

JSON →
library1.0.8jsnpmunverified

Upstash Redis storage adapter for Keyv v1.0.8, requiring Node >= 18. Built on @upstash/redis, it provides a drop-in replacement for @keyv/redis for serverless and edge environments. Supports TTL, namespaces, both CommonJS and ESM, and is fully typed. Unlike @keyv/redis, it uses HTTP-based Redis via Upstash, making it ideal for serverless functions. It is actively maintained with regular releases.

npm install keyv-upstash
INSTALL
IMPORT
SIG · KEYV-UPSTASH
K
keyv-upstash
databasejavascriptv1.0.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

KeyvUpstash
import { KeyvUpstash } from 'keyv-upstash'
import KeyvUpstash from 'keyv-upstash'
KeyvUpstash is a named export, not default. Also works with require: const { KeyvUpstash } = require('keyv-upstash').
Keyv
import Keyv from 'keyv'
const { Keyv } = require('keyv')
Keyv is a default export. CommonJS users must use require('keyv').default or const Keyv = require('keyv') (if configured).
Redis
import { Redis } from '@upstash/redis'
const Redis = require('@upstash/redis')
Redis is a named export from @upstash/redis. For CJS, use const { Redis } = require('@upstash/redis').

Shows how to create a Keyv instance with keyv-upstash using URL and token from environment variables, set and get a value.

import Keyv from 'keyv'; import { KeyvUpstash } from 'keyv-upstash'; const keyv = new Keyv({ store: new KeyvUpstash({ url: process.env.UPSTASH_REDIS_URL ?? '', token: process.env.UPSTASH_REDIS_TOKEN ?? '', }), }); await keyv.set('foo', 'bar'); const value = await keyv.get('foo'); console.log(value); // 'bar'
Debug
Known issues
gotchaautomaticDeserialization must be set to false when passing a custom Upstash Redis client to prevent issues with special value types like Buffer and BigInt.
fix
Set automaticDeserialization: false when creating the Redis instance.
affects: >=1.0.0
deprecatedDo not use automaticDeserialization: true with this adapter; it is not recommended and may cause data corruption.
fix
Always set automaticDeserialization: false (this is the default, but explicit is safer).
affects: >=1.0.0
gotchaKeyv expects the store to handle TTL via the 'ttl' option passed to the set method; keyv-upstash uses Redis TTL, but ensure you pass a numeric TTL in milliseconds.
fix
Use keyv.set('key', 'value', ttl) where ttl is milliseconds (e.g., 10000 for 10s).
affects: >=1.0.0
breakingNode.js < 18 is not supported due to engine requirement in package.json.
fix
Upgrade Node.js to version 18 or higher.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: KeyvUpstash is not a constructor
Using default import instead of named import: import KeyvUpstash from 'keyv-upstash'
fix
Use named import: import { KeyvUpstash } from 'keyv-upstash'
Error: Upstash Redis URL is required
Missing 'url' option when constructing KeyvUpstash (unless passing a custom client).
fix
Provide 'url' and 'token' options or pass a pre-configured 'upstashRedis' client.
ERR_INVALID_ARG_TYPE: The "key" argument must be of type string
Passing a non-string key to keyv.get() or keyv.set().
fix
Ensure keys are strings (Keyv coerces to string, but Upstash Redis may not).
Upgrade
Version history
1.0.8latest on npm
Audit
Dependencies
keyvrequiredPeer dependency required to create a Keyv instance with the store
@upstash/redisoptionalUnderlying Redis client for Upstash; used when passing a custom client instance
Agent activity
4 hits · last 30 days
node
4
Resources
keyv-upstash — npm install keyv-upstash · libregistry