Not connecting to Redis in the private network.
alexzayaz
PROOP

4 months ago

I have the following project structure:

Backend: ASP.NET Core + Redis + Playwright + API (updates prices from LME)
Frontend: Built via build-static.sh, placed in /dist
Dockerfile: A single file that:

  • builds the backend

  • builds the frontend

  • copies the frontend to dist/ and serves it through Nginx

Deployment: A single Railway container service (deployed from GitHub)
Redis: A separate Railway Redis instance in a private network

Below is the relevant Redis configuration code from my Program.cs:
builder.Configuration

.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)

.AddEnvironmentVariables();

var rawRedisUrl = builder.Configuration["ConnectionStrings:Redis"];

Console.WriteLine("mag emoji DEBUG: Redis from env = " + rawRedisUrl);

...

if (string.IsNullOrWhiteSpace(rawRedisUrl))

{

throw new InvalidOperationException("x emoji Redis connection string is missing.");

}

try

{

var redisUri = new Uri(rawRedisUrl);

var config = new ConfigurationOptions

{

EndPoints = { $"{redisUri.Host}:{redisUri.Port}" },

Password = redisUri.UserInfo.Split(':')[1],

User = redisUri.UserInfo.Split(':')[0],

AbortOnConnectFail = false,

Ssl = false

};

Console.WriteLine("arrows_counterclockwise emoji Redis connecting...");

var redis = await ConnectionMultiplexer.ConnectAsync(config);

var db = redis.GetDatabase();

try

{

var pong = await db.PingAsync();

Console.WriteLine("white_check_mark emoji Redis is responsive, latency: " + pong.TotalMilliseconds + "ms");

}

catch (Exception ex)

{

Console.WriteLine("x emoji Redis is not responding:");

Console.WriteLine(ex.ToString());

throw;

}

builder.Services.AddSingleton(redis);

}

catch (Exception ex)

{

Console.WriteLine("x emoji Failed to connect to Redis:");

Console.WriteLine(ex.ToString());

throw;

}

In the Redis service, I added the environment variable:

In the technology service, I exposed this variable as:

However, during deployment I get an error saying it’s not possible to connect to Redis.
I don’t understand the reason.

Attachments

Solved$10 Bounty

3 Replies

Railway
BOT

4 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


alexzayaz
PROOP

4 months ago

Deploy logs:

Attachments


alexzayaz
PROOP

4 months ago

Update:
The issue is resolved. There was an unnecessary custom start command in the Redis service under the "Custom start command" Deploy section - it was breaking the connection.
After removing it, the backend successfully connected to Redis.


Status changed to Open itsrems 4 months ago


Status changed to Solved itsrems 4 months ago


Loading...