Skip to content

SooditK/downstash

Repository files navigation

Downstash

WTFPL

An HTTP server that talks to Redis so you don't have to. Think Upstash, but you run it yourself. Or don't. I'm not your boss.

What is this?

Downstash is a lightweight HTTP API wrapper around Redis that's compatible with the Upstash REST API format. It lets you interact with Redis over HTTP using simple POST requests, which is handy when you can't (or don't want to) use a native Redis client.

Why would you want this? Maybe you're in a serverless environment. Maybe you're behind a firewall that only allows HTTP. Maybe you just like making things more complicated. Who am I to judge?

Features

  • 🚀 Upstash-compatible API - Drop-in replacement for Upstash REST API
  • 🔐 Bearer token authentication - Because security is a thing
  • 📦 Pipeline support - Batch multiple commands in one request
  • 🔄 Transaction support - MULTI/EXEC for when you need atomicity
  • 🎨 Base64 encoding - Optional encoding for binary data (Upstash style)
  • 🐳 Docker ready - Because containers are the new black
  • Built with Hono - Fast, lightweight, and actually pleasant to use

Quick Start

Prerequisites

  • Deno 2.0+ (or Docker if you're fancy)
  • A Redis instance (local or remote, we're not picky)

Installation

# Clone this thing
git clone <your-repo-url>
cd downstash

# Set up your environment
cp .env.example .env  # If you have one, otherwise just set these:
export SR_TOKEN="your-secret-token-here"
export REDIS_URL="redis://localhost:6379"
export PORT=3000  # Optional, defaults to 3000

# Run it
deno task dev

Or if you're a Docker person:

docker-compose up

API Reference

All endpoints require Bearer token authentication via the Authorization header.

Health Check

GET /

Returns a friendly welcome message. Mostly for checking if the server is alive.

Ping

GET /ping

Returns Pong. Because every API needs a ping endpoint.

Single Command

POST /
Content-Type: application/json
Authorization: Bearer your-token-here

["SET", "key", "value"]

Execute a single Redis command. The body should be an array where the first element is the command name, followed by its arguments.

Response:

{
  "result": "OK"
}

Pipeline

POST /pipeline
Content-Type: application/json
Authorization: Bearer your-token-here

[
  ["SET", "key1", "value1"],
  ["GET", "key1"],
  ["SET", "key2", "value2"]
]

Execute multiple commands sequentially. Returns an array of results.

Response:

{
  "result": [
    { "result": "OK" },
    { "result": "value1" },
    { "result": "OK" }
  ]
}

Transaction (MULTI/EXEC)

POST /multi-exec
Content-Type: application/json
Authorization: Bearer your-token-here

[
  ["SET", "key1", "value1"],
  ["GET", "key1"],
  ["INCR", "counter"]
]

Execute commands in a transaction. Currently behaves similarly to pipeline (honestly, the Redis MULTI/EXEC handling could be more sophisticated, but it works).

Response:

{
  "result": [
    { "result": "OK" },
    { "result": "value1" },
    { "result": 1 }
  ]
}

Base64 Encoding

If you want responses encoded in base64 (Upstash style), include this header:

upstash-encoding: base64

This is useful for handling binary data or when you need compatibility with Upstash clients.

Environment Variables

Variable Description Default
SR_TOKEN Bearer token for authentication (required)
REDIS_URL Redis connection URL redis://localhost:6379
PORT Server port 3000
HOST Server hostname 0.0.0.0

Deployment

Railway

This was built with Railway in mind, but honestly, it'll run anywhere Deno runs.

  1. Connect your repo to Railway
  2. Set the environment variables
  3. Deploy
  4. Profit?

Docker

docker build -t downstash .
docker run -p 3000:3000 \
  -e SR_TOKEN=your-token \
  -e REDIS_URL=redis://your-redis:6379 \
  downstash

How It Works

  1. You send an HTTP request with a Redis command
  2. The server validates your token (or doesn't, if you didn't set one up properly)
  3. It parses your command and sends it to Redis via ioredis
  4. Redis does its thing
  5. The server formats the response in Upstash-compatible JSON
  6. You get your result (or an error, if you messed something up)

The codebase is pretty straightforward - no magic, just HTTP → Redis → HTTP. The most complex part is probably the base64 encoding logic, and even that's not rocket science.

Technologies Used

  • Hono - A lightweight, fast web framework. Actually good.
  • Deno - A secure runtime that doesn't make you deal with node_modules
  • ioredis - Redis client that actually works

Limitations & Quirks

  • Transactions (/multi-exec) currently just run commands sequentially. Real MULTI/EXEC support could be added, but it works for most use cases.
  • Error handling is basic but functional. Don't expect poetry in error messages.
  • The code assumes you know what you're doing with Redis commands. It won't hold your hand.

License

WTFPL - Do What The F*ck You Want To Public License

You want to use this? Go ahead. Modify it? Sure. Sell it? Whatever. Just don't blame me if something breaks.


Made with questionable amounts of coffee and a healthy dose of pragmatism.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published