upstash / docs

Upstash documentation
https://upstash.com/docs/
9 stars 44 forks source link

Missing documentation on UPSTASH_REDIS_REST_URL #184

Open pboling opened 6 months ago

pboling commented 6 months ago

Problem 1

There is no documentation on where to find the correct values for the following environment variables:

UPSTASH_REDIS_REST_URL
UPSTASH_REDIS_REST_TOKEN

This (very out of date) document says to look for a REST_URL on the dashboard, but that doesn't exist.

The dashboard appears to have been updated significantly since those screenshots, and now there is a many tabbed "Connect to your database" widget.

Unfortunately it does not have an ENV shell variable section, which is what I need for Fly.io deployment.

Other documentation appears to imply that we'd get the values from the info printed at the end of the flyctl create redis script, but the values, if they were given, were missed by me, and I copied the entire output, and still have it, perhaps they were disguised so as to appear to be relevant to something else.

Solution 1

"Connect to your database" widget should have an ENV section for the ENV variable version of the connection info.

Problem 2

Perhaps my confusion is that the value given by the script starts with redis://, and I've seen other documentation indicating that UPSTASH_REDIS_REST_URL is intended for HTTP REST interactions, so I'm expecting it to start with HTTP, and indeed, some of the "Connect to a database" examples do have URLs starting with HTTP.

A second issue then is that the flyctl integration gives bad output that isn't relevant to what we actually need to setup Upstash Redis on our Fly.io apps.

What the output has currently (totally misleading / irrelevant to a Fly.io app needing UPSTASH_REDIS_REST_URL)

Your database some-some-some-<num> is ready. Apps in the fisecal org can connect to Redis at redis://default:do-de-do-de-do-de-do-de@fly-some-some-some-<num>.upstash.io:6379

If you have redis-cli installed, use fly redis connect to get a Redis console.

Your database is billed at $0.20 per 100K commands. If you're using Sidekiq or BullMQ, which poll Redis frequently, consider switching to a fixed-price plan. See https://fly.io/docs/reference/redis/#pricing

Solution 2

Fix the output for the flyctl integration to give users the necessary info, namely:

UPSTASH_REDIS_REST_URL
UPSTASH_REDIS_REST_TOKEN
pboling commented 6 months ago

Reading here: https://upstash.com/docs/redis/quickstarts/fly

It is clear that UPSTASH_REDIS_REST_URL isn't relevant to Fly, and info I found in that direction is out of data / incorrect.

We just need in our fly.toml [[services]] section:

[env]
  REDIS_URL = "<your-upstash-redis-url>"

where the URL is a URL from the Upstash dashboard. I am still not sure which one exactly, but it is more clear now. Maybe it can be the redis:// URL from the flyctl output?

pboling commented 6 months ago

Oh, but that's not going to work, fly.toml is tracked in git. We can't put secret tokens in there. The documentation is not just wrong, it is dangerous.

pboling commented 6 months ago

The only safe and reasonable answer is in the example code for setting up a local tunnel, which is very strange. This should be the primary documentation.

const redis = require("redis");

// Local Redis URL for development
const LOCAL_REDIS_URL = 'redis://localhost:10000'; // Replace with your actual local address
const REDIS_URL = process.env.NODE_ENV === 'development' ? LOCAL_REDIS_URL : process.env.REDIS_URL;

const client = redis.createClient({
    url: REDIS_URL
});

client.on("error", function(error) {
  console.error(error);
});

// Rest of your Redis-related code

Ref: https://upstash.com/docs/redis/quickstarts/fly#example-code-for-setting-up-and-using-the-fly-io-redis-tunnel