Skip to content

Repository files navigation

upstash-redis-local

A local webserver for testing and development using @upstash/redis

πŸ“– Full Documentation β†’ | Preview locally: cd docs && mint dev

πŸ€” What is upstash-redis-local?

The upstash-redis-local command starts a local web server that provides a REST API compatible with Upstash REST API. It connects to a real Redis database instance, making it perfect for local development and testing.

Key Features:

  • βœ… Compatible with @upstash/redis SDK
  • βœ… Unlimited local requests β€” no cloud rate limits or daily quotas
  • βœ… Full REST API: /pipeline, /multi-exec, /publish, /subscribe, /monitor
  • βœ… Read-only token support (like Upstash cloud)
  • βœ… Usage dashboard at /dashboard β€” see cloud quota saved
  • βœ… Rate-limit simulator (--simulate-quota, --simulate-rps)
  • βœ… QStash emulator β€” local HTTP message queue with delays, retries, DLQ (--enable-qstash)
  • βœ… Chaos injection β€” simulate slow/flaky Upstash (--inject-latency, --inject-error-rate)
  • βœ… Cloud-parity strict mode β€” catch "works locally, breaks in prod" (--strict-upstash)
  • βœ… Record & replay β€” capture a session and replay it (--record, upstash-local replay)
  • βœ… Security hardening: --secure, dashboard auth, dangerous-command blocking
  • βœ… CORS enabled for browser/edge dev
  • βœ… Docker Compose profiles: default, external Redis, Redis Stack
  • βœ… CLI tools: upstash-local use dev, seed, export, import, generate-token, replay
  • βœ… Connection pooling + graceful shutdown
  • βœ… Tiny Docker image (~10MB)

This project is inspired by upstashdis but uses fasthttp for better performance.

πŸ’» Usage

upstash-redis-local v1.0
A local server that mimics upstash-redis for local testing purposes!

       * Connect to any local redis of your choice for testing
       * Completely mimics the upstash REST API https://docs.upstash.com/redis/features/restapi

USAGE:
    upstash-redis-local
    upstash-redis-local --token upstash --addr :8000 --redis :6379

ARGUMENTS:
    --token       TOKEN  The API token to accept as authorised (default: upstash)
    --addr        ADDR   Address for the server to listen on (default: :8000)
    --redis       ADDR   Address to your redis server (default: :6379)
    --max-retries N      Max connection retries on startup (default: 10)
    --retry-delay MS     Delay between retries in milliseconds (default: 1000)
    --help               Prints this message

ENVIRONMENT VARIABLES:
    REDIS_ADDR     Redis server address (alternative to --redis)
    UPSTASH_ADDR   Webserver address (alternative to --addr)
    UPSTASH_TOKEN  API token (alternative to --token)

πŸš€ Quick Start

chmod +x start.sh
./start.sh

Then open:

Switch your app to local (no rate limits)

make build-cli
./bin/upstash-local use dev
# Point your app at .env.local β€” unlimited requests, zero cloud quota

See .env.example for cloud vs local profiles.

πŸ“Š Dashboard & Rate Limit Tools

Open http://localhost:8000/dashboard to see:

  • Total requests (unlimited locally)
  • Cloud quota saved vs Upstash free tier (10k/day)
  • Key browser

Simulate cloud limits for testing fallback logic:

upstash-redis-local --simulate-quota 10000 --simulate-rps 100

πŸ§ͺ Testing & Reliability Tools

# Simulate a slow, flaky Upstash (test your retry/fallback logic)
upstash-redis-local --inject-latency 200 --inject-error-rate 0.1

# Reject commands Upstash REST doesn't support (catch prod bugs early)
upstash-redis-local --strict-upstash

# Record every command, then replay the session later
upstash-redis-local --record session.jsonl
./bin/upstash-local replay --input session.jsonl

See docs/guides/testing-tools.mdx.

πŸ“¨ QStash Emulator

A local HTTP message queue (like Upstash QStash) for background jobs, webhooks, and email/notification queues:

upstash-redis-local --enable-qstash

# Queue a message for delivery to a URL (with retries + DLQ)
curl -X POST "http://localhost:8000/v2/publish/?url=https://example.com/webhook" \
  -H "Authorization: Bearer local-dev-token" \
  -H "Upstash-Delay: 10s" \
  -d '{"email":"welcome@app.com"}'

curl http://localhost:8000/v2/messages -H "Authorization: Bearer local-dev-token"
curl http://localhost:8000/v2/dlq -H "Authorization: Bearer local-dev-token"

See docs/guides/qstash.mdx.

πŸ”§ CLI Commands

make build-cli
./bin/upstash-local use dev      # Switch to local (unlimited)
./bin/upstash-local use cloud    # Switch to cloud (.env.cloud required)
./bin/upstash-local status       # Show active profile
./bin/upstash-local seed --keys 1000 --prefix dev:
./bin/upstash-local export --output dump.json
./bin/upstash-local import --input dump.json
./bin/upstash-local ping

🐳 Docker Compose Profiles

# Default β€” bundled Redis
docker compose up -d

# External Redis (when port 6379 already in use)
docker compose --profile external up -d upstash-local-external

# Redis Stack (JSON module support)
docker compose --profile stack up -d

⬇ Installation

Using Docker Compose (Recommended)

The easiest way to get started:

# Clone the repository
git clone https://github.com/aine1100/Upstash-Redis-Local-server.git
cd upstash-redis-local

# Start Redis and upstash-redis-local
docker-compose up -d

# Test the connection
curl -H "Authorization: Bearer local-dev-token" http://localhost:8000/PING

Quick Start (Automated Script)

On Windows (Git Bash/WSL), macOS, or Linux, you can use the provided startup script:

chmod +x start.sh
./start.sh

This script will:

  1. Check if Docker is running.
  2. Attempt to start Docker Desktop if it's closed.
  3. Start the containers using docker-compose up -d.

Using Docker

# Run with a local Redis
docker run --rm -p 8000:8000 darthbenro008/upstash-redis-local:latest --redis host.docker.internal:6379

# Or link to a Redis container
docker run -d --name redis redis:7-alpine
docker run --rm -p 8000:8000 --link redis:redis darthbenro008/upstash-redis-local:latest --redis redis:6379

Using Homebrew

brew tap aine1100/Upstash-Redis-Local-server
brew install upstash-redis-local

Building from Source

# Clone and build
git clone https://github.com/aine1100/Upstash-Redis-Local-server.git
cd upstash-redis-local
make build

# Run
./bin/upstash-redis-local --redis :6379

Manual Installation

Download the latest release from the releases page for your OS.

πŸ” Authentication

The server requires an API token to authorize requests. By default, this token is local-dev-token (when using Docker Compose) or upstash.

1. In the Browser

Append the _token query parameter to your URL: http://localhost:8000/PING?_token=local-dev-token

Browser PING Result

2. In the API Tool (Postman)

  • URL: http://localhost:8000/KEYS/*
  • Auth Type: Select API Key
  • Key: _token
  • Value: local-dev-token
  • Add to: Query Params (Recommended)

Postman Authentication Setup

Postman KEYS Result

3. Using cURL

curl -H "Authorization: Bearer local-dev-token" http://localhost:8000/PING
# OR
curl "http://localhost:8000/PING?_token=local-dev-token"

πŸ”§ Using with @upstash/redis

import { Redis } from '@upstash/redis'

const redis = new Redis({
  url: 'http://localhost:8000',
  token: 'local-dev-token', // or your custom token
})

// Use normally
await redis.set('foo', 'bar')
const value = await redis.get('foo')
console.log(value) // 'bar'

🐳 Docker Compose Configuration

The included docker-compose.yml provides:

  • Redis 7 with health checks
  • upstash-redis-local with automatic retry
  • Persistent Redis data volume
services:
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
  
  upstash-local:
    build: .
    ports:
      - "8000:8000"
    environment:
      - REDIS_ADDR=redis:6379
      - UPSTASH_TOKEN=local-dev-token
    depends_on:
      redis:
        condition: service_healthy

πŸ” Viewing the Database

There are several ways to view and manage your local data:

1. Using Redis CLI (Inside Docker)

You can jump into the Redis container to run raw commands:

docker exec -it upstash-redis-local-redis-1 redis-cli
# Then try:
> keys *
> get foo

2. Using Redis Insight (GUI)

Redis Insight is a free, powerful GUI for Redis.

  • Host: localhost
  • Port: 6379
  • Password: (none by default)

3. Using HTTP Requests

Since this project mimics Upstash, you can just use your browser or curl:

  • Get all keys: http://localhost:8000/KEYS/*?_token=local-dev-token
  • Get value: http://localhost:8000/GET/mykey?_token=local-dev-token

Note

If you see random strings like "YnVsb0...", it means you were viewing raw bytes. This has been fixed to return readable strings.


πŸ” Troubleshooting

Connection Refused

If you see connection refused errors:

  1. Ensure Redis is running: redis-cli ping
  2. Check the address format: --redis localhost:6379 (not just :6379)
  3. In Docker, use the service name: --redis redis:6379

Docker Networking

When running in Docker, use:

  • host.docker.internal:6379 to connect to Redis on host machine
  • The service name (e.g., redis:6379) when using Docker Compose

🀝 Contributions

βš– License

Copyright 2024 Hemanth Krishna

Licensed under MIT License: https://opensource.org/licenses/MIT

Made with ❀ and a single cup of kofi

About

This repo contains a simple setup of upstash redis server for those who face rate limits in free modes

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages