Anonymous
TRIALOP
3 years ago
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:password@containers-us-west-174.railway.app: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
13 Replies
3 years ago
- please use environment variables in your code, never hardcore secrets/credentials
- have you setup the redis variable references in your service variables?
- I was doing a quick test to see if it would've connected so I didn't bother using env vars
- What variables would need to be setup? After I created the service there were already variables
3 years ago
how long ago did you create the service?
3 years ago
then you would need to setup the variable references in the service variables tab
3 years ago
scroll down to the reference variables section
If you mean that I need to reference plugin variables in the service env vars then
- the project is still not hosted on railway so there is no point in doing it and
- why would that not be a problem when connecting using
redis-cli railway_redis_url?
After a bit of experimenting I found out that GetDatabase() needs a database number and that is causing the error