NutsNews Worker Upstash Redis Update
Section titled “NutsNews Worker Upstash Redis Update”This update adds optional Upstash Redis support to the Cloudflare Worker shard refresh flow.
What Redis does in this update
Section titled “What Redis does in this update”- 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-statusto 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.
Required Upstash values
Section titled “Required Upstash values”In the Upstash dashboard, open your Redis database, go to the REST connection section, and copy:
UPSTASH_REDIS_REST_URLUPSTASH_REDIS_REST_TOKEN
Use the standard token, not the read-only token, because the Worker needs write commands for locks and counters.
Cloudflare Secrets Store secrets
Section titled “Cloudflare Secrets Store secrets”Add these two secrets to the same Cloudflare Secrets Store already used by the Worker:
UPSTASH_REDIS_REST_URLUPSTASH_REDIS_REST_TOKEN
Wrangler generator flags
Section titled “Wrangler generator flags”To bind the Upstash secrets into every generated shard config, run the generator with:
export ENABLE_UPSTASH_REDIS_SECRET_BINDING=trueexport UPSTASH_REDIS_ENABLED=trueOptional tuning values:
export UPSTASH_REDIS_WORKER_LOCK_TTL_SECONDS=600export UPSTASH_REDIS_AI_REVIEW_LOCK_TTL_SECONDS=1800export UPSTASH_REDIS_MANUAL_RATE_LIMIT_MAX=20export UPSTASH_REDIS_MANUAL_RATE_LIMIT_WINDOW_SECONDS=3600export UPSTASH_REDIS_COUNTER_TTL_SECONDS=259200Verify after deploy
Section titled “Verify after deploy”Open one shard’s status endpoint:
curl "https://nutsnews-worker-0.nutsnews.workers.dev/redis-status"Expected when configured:
{ "redisEnabled": true, "ping": "PONG"}Run one small manual refresh:
curl "https://nutsnews-worker-0.nutsnews.workers.dev/?limit=1"The response should include:
redisEnabled: trueredisAiReviewLockAcquiredCountredisAiReviewLockSkippedCountredisStatsSaveOk
Rollback
Section titled “Rollback”Disable Redis without removing the code:
export ENABLE_UPSTASH_REDIS_SECRET_BINDING=trueexport UPSTASH_REDIS_ENABLED=falsenpm run generate:wranglernpm run deploy:allOr remove the Upstash secret binding export and regenerate/deploy.
