Closed william19821101 closed 10 months ago
I'm intrigued - those two things should be functionally identical... I'll see what I can find.
With a local hosts
entry for redis
, this works fine:
using StackExchange.Redis;
using var muxer = ConnectionMultiplexer.Connect("redis,abortConnect=false,password=xxx");
var ttl = await muxer.GetDatabase().PingAsync();
Console.WriteLine($"connected; ttl={ttl.TotalMilliseconds}ms");
with output:
connected; ttl=0.6956ms
Do you have a runnable repro? I'm not seeing any failure here. Also: what library version are you using? Finally, is there a stack trace on that message, so we can see where it is originating?
I think what you're actually doing is this:
var server = muxer.GetServer("redis");
Now, that parameter is called hostAndPort
, and that: currently requires the port. I think the real question here is:
Can
GetServer(string)
apply the same default port logic thatConnect
uses when parsing endpoints referred only as a host?
That's not a terrible idea, but today: it doesn't do that.
Workaround for today:
var server = muxer.GetServer(muxer.GetEndPoints().Single());
or
var server = muxer.GetServers().Single();
So: I did a spike, and the changes needed to do this aren't huge, but: it adds complexity. The only scenario I can think of when people don't want to be really precise with their endpoints is: single endpoint - and in that scenario, the two approaches shown above already give a simple solution. They're also more efficient, I think - as to do this the magic way would require two sets of endpoint allocation.
IMO: leave it alone.
Before I conclude that, have I correctly interpreted the scenario, and do the workarounds shown above work?
Hi Marc, Thank you for correcting my question accurately. Yes, I did what you thought I hadn't mentioned in my post, and that seems to be the point. var server = muxer.GetServer("redis");
And I've tried your solution that perfectly meets my needs.
I am developing an ASP.NET Core project and using StackExchange.Redis to connect to a Redis instance running in a Docker container. My .NET project is also running in a Docker container, and both containers are in the same Docker bridge network.
The Redis container is named "redis", so this way works => ConnectionMultiplexer.Connect("redis:6379,abortConnect=false,password=xxx")
However, if I remove the port from the connection string, it doesn't work => ConnectionMultiplexer.Connect('redis,abortConnect=false,password=xxx'). I receive the message: "The specified endpoint is not defined (Parameter 'endpoint')"
I'm aware that we can use container name as a host to connect without specifying the port in the same Docker bridge network. But is it necessary to include the port in the StackExchange.Redis connection?