C# StackExchange.Redis client failing to connect

I have deployed a Redis instance and I'm trying to connect to it using StackExchange.Redis but i get the error "It was not possible to connect to the redis server(s)".
using StackExchange.Redis;

namespace Redis
{
public class Client
{
public static readonly ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(
new ConfigurationOptions()
{
EndPoints = { "redis://default:[email protected]:5494" }
}
);

public static double Ping()
{
var db = redis.GetDatabase();
var ping = db.Ping();

return ping.TotalMicroseconds;
}
}
}
using StackExchange.Redis;

namespace Redis
{
public class Client
{
public static readonly ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(
new ConfigurationOptions()
{
EndPoints = { "redis://default:[email protected]:5494" }
}
);

public static double Ping()
{
var db = redis.GetDatabase();
var ping = db.Ping();

return ping.TotalMicroseconds;
}
}
}
but if I connect using the cli it works
8 Replies
Percy
Percy2y ago
Project ID: 0f54028f-2b4f-45ff-85ca-e7f3f2f1a4ea
iKingNinja
iKingNinjaOP2y ago
0f54028f-2b4f-45ff-85ca-e7f3f2f1a4ea
Brody
Brody2y ago
1. please use environment variables in your code, never hardcore secrets/credentials 2. have you setup the redis variable references in your service variables?
iKingNinja
iKingNinjaOP2y ago
1. I was doing a quick test to see if it would've connected so I didn't bother using env vars 2. What variables would need to be setup? After I created the service there were already variables
Brody
Brody2y ago
how long ago did you create the service?
iKingNinja
iKingNinjaOP2y ago
5 minutes before I created this post
Brody
Brody2y ago
then you would need to setup the variable references in the service variables tab https://docs.railway.app/develop/variables scroll down to the reference variables section
iKingNinja
iKingNinjaOP2y ago
If you mean that I need to reference plugin variables in the service env vars then 1) the project is still not hosted on railway so there is no point in doing it and 2) why would that not be a problem when connecting using redis-cli railway_redis_url? Wdym then? I have an update After a bit of experimenting I found out that GetDatabase() needs a database number and that is causing the error So how do I get the database number?
Want results from more Discord servers?
Add your server