Skip to content

Simple guide · Overview

Page status: HistoricalHistory group: Updates

NutsNews Worker Upstash Redis Update

This update adds optional Upstash Redis support to the Cloudflare Worker shard refresh flow.

Visual overview

Primary diagram

System map

This update adds optional Upstash Redis support to the Cloudflare Worker shard refresh flow.

Render the repository-owned system map when you need it.

Diagram is not rendered yet.

View as text
NutsNews Worker Upstash Redis Update

This update adds optional Upstash Redis support to the Cloudflare Worker shard refresh flow.

flowchart TB
  accTitle: NutsNews Worker Upstash Redis Update
  accDescr {
    This update adds optional Upstash Redis support to the Cloudflare Worker shard refresh flow.
  }
  A["NutsNews Worker Upstash Redis Update"] --> B["updates/UPSTASH_REDIS_WORKER_UPDATE_README.md"]
  B --> C["Auto-generated placeholder diagram"]

NutsNews Worker Upstash Redis Update

Fullscreen diagram view.

This update adds optional Upstash Redis support to the Cloudflare Worker shard refresh flow.

  • Adds a short-lived worker shard lock so the same shard does not run twice at the same time.
  • Adds per-article AI review locks so two Worker runs do not spend AI calls reviewing the same URL at the same time.
  • Adds a Redis-backed rate limit for manual Worker refresh requests.
  • Adds short-lived Redis counters for daily manual runs, scheduled runs, AI reviewed count, accepted count, and rejected count.
  • Adds /redis-status to confirm Redis is connected and view the temporary counters.

Redis is optional. If UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN are missing, the Worker keeps running without Redis.

In the Upstash dashboard, open your Redis database, go to the REST connection section, and copy:

  • UPSTASH_REDIS_REST_URL
  • UPSTASH_REDIS_REST_TOKEN

Use the standard token, not the read-only token, because the Worker needs write commands for locks and counters.

Add these two secrets to the same Cloudflare Secrets Store already used by the Worker:

  • UPSTASH_REDIS_REST_URL
  • UPSTASH_REDIS_REST_TOKEN

To bind the Upstash secrets into every generated shard config, run the generator with:

Terminal window
export ENABLE_UPSTASH_REDIS_SECRET_BINDING=true
export UPSTASH_REDIS_ENABLED=true

Optional tuning values:

Terminal window
export UPSTASH_REDIS_WORKER_LOCK_TTL_SECONDS=600
export UPSTASH_REDIS_AI_REVIEW_LOCK_TTL_SECONDS=1800
export UPSTASH_REDIS_MANUAL_RATE_LIMIT_MAX=20
export UPSTASH_REDIS_MANUAL_RATE_LIMIT_WINDOW_SECONDS=3600
export UPSTASH_REDIS_COUNTER_TTL_SECONDS=259200

Open one shard’s status endpoint:

Terminal window
curl "https://nutsnews-worker-0.nutsnews.workers.dev/redis-status"

Expected when configured:

{
"redisEnabled": true,
"ping": "PONG"
}

Run one small manual refresh:

Terminal window
curl "https://nutsnews-worker-0.nutsnews.workers.dev/?limit=1"

The response should include:

  • redisEnabled: true
  • redisAiReviewLockAcquiredCount
  • redisAiReviewLockSkippedCount
  • redisStatsSaveOk

Disable Redis without removing the code:

Terminal window
export ENABLE_UPSTASH_REDIS_SECRET_BINDING=true
export UPSTASH_REDIS_ENABLED=false
npm run generate:wrangler
npm run deploy:all

Or remove the Upstash secret binding export and regenerate/deploy.