Skip to content

HTTP based Redis Client for Serverless and Edge Functions

License

Notifications You must be signed in to change notification settings

upstash/redis-js

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Oct 19, 2023
dd9731d · Oct 19, 2023
Oct 19, 2023
Oct 19, 2023
Oct 19, 2023
Oct 19, 2023
Oct 19, 2023
Dec 1, 2021
Dec 19, 2022
May 23, 2022
May 6, 2022
Oct 19, 2023
Oct 19, 2023
Oct 19, 2023
Oct 19, 2023
Aug 2, 2022
Oct 18, 2023
Oct 19, 2023
Oct 19, 2023
Oct 19, 2023
Oct 19, 2023
Oct 19, 2023
Oct 19, 2023
May 31, 2023

Repository files navigation

Upstash Redis

@upstash/redis is an HTTP/REST based Redis client for typescript, built on top of Upstash REST API.

Tests npm (scoped) npm bundle size

It is the only connectionless (HTTP based) Redis client and designed for:

  • Serverless functions (AWS Lambda ...)
  • Cloudflare Workers (see the example)
  • Fastly Compute@Edge (see the example)
  • 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

Node.js

npm install @upstash/redis

Deno

import { Redis } from "https://deno.land/x/upstash_redis/mod";

Create database

Create a new redis database on upstash

Basic Usage:

import { Redis } from "@upstash/redis"

const redis = new Redis({
  url: <UPSTASH_REDIS_REST_URL>,
  token: <UPSTASH_REDIS_REST_TOKEN>,
})

// string
await redis.set('key', 'value');
let data = await redis.get('key');
console.log(data)

await redis.set('key2', 'value2', {ex: 1});

// sorted set
await redis.zadd('scores', { score: 1, member: 'team1' })
data = await redis.zrange('scores', 0, 100 )
console.log(data)

// list
await redis.lpush('elements', 'magnesium')
data = await redis.lrange('elements', 0, 100 )
console.log(data)

// hash
await redis.hset('people', {name: 'joe'})
data = await redis.hget('people', 'name' )
console.log(data)

// sets
await redis.sadd('animals', 'cat')
data  = await redis.spop('animals', 1)
console.log(data)

Troubleshooting

We have a dedicated page for common problems. If you can't find a solution, please open an issue.

Docs

See the documentation for details.

Contributing

Database

Create a new redis database on upstash and copy the url and token

Running tests

UPSTASH_REDIS_REST_URL=".." UPSTASH_REDIS_REST_TOKEN=".." deno test -A

Telemetry

This library sends anonymous telemetry data to help us improve your experience. We collect the following:

You can opt out by setting the UPSTASH_DISABLE_TELEMETRY environment variable to any truthy value.

UPSTASH_DISABLE_TELEMETRY=1