22 days 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
3 Replies
22 days 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!
22 days 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 • 22 days ago
Status changed to Solved itsrems • 22 days ago