Redis 中文文档 Redis 中文文档
指南
redis.io (opens new window)
指南
redis.io (opens new window)
  • 关于
    • Redis 开源治理
    • Redis 发布周期
    • Redis 赞助商
  • 入门
  • 数据类型
  • Redis Stack
  • 命令
  • 手册

Upstash Redis


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

Tests

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


  1. ``` shell
  2. npm install @upstash/redis
  3. ```

Deno


  1. ``` ts
  2. import { Redis } from "https://deno.land/x/upstash_redis/mod.ts";
  3. ```

Create database


Create a new redis database on upstash

Basic Usage:


  1. ``` ts
  2. import { Redis } from "@upstash/redis"

  3. const redis = new Redis({
  4.   url: <UPSTASH_REDIS_REST_URL>,
  5.   token: <UPSTASH_REDIS_REST_TOKEN>,
  6. })

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

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

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

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

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

  24. // sets
  25. await redis.sadd('animals', 'cat')
  26. data  = await redis.spop('animals', 1)
  27. console.log(data)
  28. ```

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


Install Deno


Database


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

Running tests


  1. ``` shell
  2. UPSTASH_REDIS_REST_URL=".." UPSTASH_REDIS_REST_TOKEN=".." deno test -A
  3. ```

Telemetry


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

SDK version
Platform (Deno, Cloudflare, Vercel)
Runtime version (node@18.x )

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

  1. ``` shell
  2. UPSTASH_DISABLE_TELEMETRY=1
  3. ```
Last Updated: 2023-09-03 19:17:54