Package Exports
- @upstash/redis
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@upstash/redis) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Upstash Redis
An HTTP/REST based Redis client built on top of Upstash REST API.
It is the only connectionless (HTTP based) Redis client and designed for:
- Serverless functions (AWS Lambda ...)
- Cloudflare Workers (see the example)
- Fastly Compute@Edge
- Next.js, Jamstack ...
- Client side web/mobile applications
- WebAssembly
- and other environments where HTTP is preferred over TCP.
See the list of APIs supported.
Quick Start
Install
npm install @upstash/redisUsage with Promise
import { auth, set } from '@upstash/redis';
auth('UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN');
set('key', 'value').then(({ data }) => {
console.log(data);
// -> "OK"
});Usage with async/await
import { set } from '@upstash/redis';
(async () => {
try {
const { data, error } = await set('key', 'value');
if (error) throw error;
console.log(data);
// -> "OK"
} catch (error) {
console.error(error);
}
})();If you define
UPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKENenvironment variables, you can skip the auth().
Edge Support
Once you set edgeUrl, all read commands are fetched using edge url. The REST URL is used for write/update commands.
import { auth, get } from '@upstash/redis';
auth({
url: 'UPSTASH_REDIS_REST_URL',
token: 'UPSTASH_REDIS_REST_TOKEN',
edgeUrl: 'UPSTASH_REDIS_EDGE_URL',
});
(async () => {
try {
// the below reads using edge url
const { data, error, metadata } = await get('key');
if (error) throw error;
console.log(data);
// -> null | string
console.log(metadata);
// -> { edge: boolean, cache: null | 'miss' | 'hit' }
// the below reads using REST url (non-edge)
const get1 = await get('key', { edge: false });
if (get1.error) throw get1.error;
} catch (error) {
console.error(error);
}
})();Docs
See the documentation for details.