Upstash Redis

Hi,

I am trying to review the Upstash Redis solution provided by fly, but having some difficulties and also some questions. Maybe someone can help out with more information.

The first doubt I have is if the database provided here is fully compatible with Redis, meaning TCP persistent connection and Redis commands, or if it’s a serverless flavor where only the REST API can be used?

I am able to connect to the database using the fly redis connect ... CLI command, but through my application it doesn’t seem to work.

I can’t argue the database isn’t available to the app, because running the following command tells me that the address can be resolved

$ fly dig database-name.upstash.io                                                                      
;; opcode: QUERY, status: NOERROR, id: 24545
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; QUESTION SECTION:
;database-name.upstash.io.	IN	 AAAA

;; ANSWER SECTION:
database-name.upstash.io.	15	IN	AAAA	fdaa:1:1:1:1::1

;; ADDITIONAL SECTION:

;; OPT PSEUDOSECTION:
; EDNS: version 0; flags: ; udp: 4096

So… The reason I can’t connect is either because it only supports REST API or because I’m doing something wrong in the configuration string.

The database URI looks like this

redis://default:password@database-name.upstash.io

And the configuration string should look like this

database-name.upstash.io,user=default,password=password,ssl=true

Any feedback would be much appreciated.

Updates…

I’ve created a free database on Upstash directly and I’ve managed to connect to that one; actually I created two, one with TLS and another without, both cases I can connect. So… maybe the application isn’t “seeing” the database after all or… something I’m not seeing.

I’ve double checked the regions and both the application and database are in the same region (ams).

Does anyone from fly actually ever responds here?

I needed to add ?family=6 to my connection string to get the connection working to my upstash Redis DB from Fly as it uses an IPv6 connection. Similar to comments here: Connecting to Redis App

Maybe that will work for you.

@goncalo-oliveira Did you resolve this? In most cases, this can happen because of lacking to set the IPv6 family on Node clients, related to what @Stephen mentioned here.

I needed to add ?family=6 to my connection string to get the connection working to my upstash Redis DB from Fly as it uses an IPv6 connection

Thanks for the reply @Stephen and apologies for the late reply. Though, that didn’t work. Those similar comments refer to Node clients, which is not the case. I’m using .NET and StackExchange’s redis client, which fully supports IPv6.

@jsierles thanks for the reply. I haven’t, no. Can only connect to an Upstash Redis created on their platform directly.

@jsierles the Fly version of redis deployed, does it have SSL enabled? Is the default port being used, as indicated by the URI?

No SSL enabled since the connection is already encrypted over the Fly private network. And yes, Upstash Redis uses the default port. You must be running your app in the same organization as the Redis instance.

@jsierles thanks for the reply. Though, I have no idea what might be the issue then. I’ve tried all sorts of combinations (with and without SSL) and no luck. As I said before, both are in the ams region.

$ fly redis list  
map[eviction:true]
NAME          	ORG     	PLAN	EVICTION	PRIMARY REGION
green-sky-9960	personal	Free	Enabled 	ams

$ fly apps list
NAME                         	OWNER   	STATUS   	PLATFORM
fly-builder-polished-surf-206	personal	suspended	machines
holy-sun-7268                	personal	running  	nomad

$ fly regions list -a holy-sun-7268
Region Pool: 
ams
Backup Region: 

$ fly dig fly-green-sky-9960.upstash.io
;; opcode: QUERY, status: NOERROR, id: 45899
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; QUESTION SECTION:
;fly-green-sky-9960.upstash.io.	IN	 AAAA

;; ANSWER SECTION:
fly-green-sky-9960.upstash.io.	15	IN	AAAA	fdaa:1:2026:0:1::2

;; ADDITIONAL SECTION:

;; OPT PSEUDOSECTION:
; EDNS: version 0; flags: ; udp: 4096

The connection error is the following, just for clarification

It was not possible to connect to the redis server(s). UnableToConnect on fly-green-sky-9960.upstash.io:6379/Interactive

Any ideas?

Ok, an update…

I tried using the IP address instead of the domain name and that worked…

configuration=fdaa:1:2026:0:1::2,password=[redacted]

So… weird one since the dig command says the domain resolves to that address. Could that be failing to resolve from the App?

I’ve added an endpoint to resolve the domain and spit out the IP addresses and it seems to be resolving correctly from the app

[
    "fdaa:1:2026:0:1::2"
]

That does point out to an issue with the Redis client from Stackexchange, since connecting with the IP does work.

@jsierles do you know how often these IP addresses change (for redis)?

A potential workaround (until this is fixed) could be to resolve the domain before connecting.

Ok, this is sorted. The client does support IPv6 and a bug was fixed and released in December.

Because I was using the client through a microsoft caching package (Microsoft.Extensions.Caching.StackExchangeRedis) I was loading an older version without that fix, so… not working. That was addressed here.

Updating the client package did the trick. All sorted!

Thanks to all and hopefully this can help someone else.

2 Likes

Hi,

I am trying this but can’t connect. Do you have any advice?

ConnectionMultiplexer.Connect(“fdaa:1:250f:0:1::2,user=default,password=6a62991f167545a396a6a06d92411111”)

I tried to do what you say but did not work.

Hi @zormax sorry for the late reply…

You’re using StackExchange to connect as well? What’s the version of the package you’re using? Or are you using the distributed caching packages (Microsoft.Extensions.Caching.StackExchangeRedis)?

1 Like

Hi @goncalo-oliveira,

Thanks for your kind help. I am using StackExchange.Redis 2.6.70.

My connection URL is: redis://default:6a62991f167545a396a6a06d924113ab@fly-ecommerce-max-redis.upstash.io

Trying to connect with this code block:

Do you have any idea how I can connect?

You’re not using the latest version of the redis client package. Shouldn’t matter, since the IPv6 bug was sorted out with 2.6.62, but I guess it wouldn’t hurt to update.

From your redis URL, the configuration string should look something like this (just replace with your redis IPv6)

fdaa:1:2020:0:1::2,password=6a62991f167545a396a6a06d924113ab

That should work inside the deployed application. At least it worked for me. If not, maybe confirm the redis instance is in the same region as the app.

Also, just to be clear… using the updated StackExchange.Redis works with domain name… doesn’t have to be the IPv6.

In your case…

fly-ecommerce-max-redis.upstash.io,password=6a62991f167545a396a6a06d924113ab
1 Like

It is working. Many thanks to you. You are a very helpful man

1 Like