Not connecting to Redis in the private network.
alexzayaz
PROOP

10 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("🔍 DEBUG: Redis from env = " + rawRedisUrl);

...

if (string.IsNullOrWhiteSpace(rawRedisUrl))

{

throw new InvalidOperationException(" 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("🔄 Redis connecting...");

var redis = await ConnectionMultiplexer.ConnectAsync(config);

var db = redis.GetDatabase();

try

{

var pong = await db.PingAsync();

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

}

catch (Exception ex)

{

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

Console.WriteLine(ex.ToString());

throw;

}

builder.Services.AddSingleton(redis);

}

catch (Exception ex)

{

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

Console.WriteLine(ex.ToString());

throw;

}

In the Redis service, I added the environment variable:

ConnectionStrings__Redis = ${{REDIS_URL}}

In the technology service, I exposed this variable as:

ConnectionStrings__Redis = ${{Redis.ConnectionStrings__Redis}}

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

10 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

10 months ago

Deploy logs:

Attachments


alexzayaz
PROOP

10 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 nico 10 months ago


Status changed to Solved nico 10 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...