简体   繁体   中英

StackExchange.Redis failing to connect with Mono in Mac OS X

I'm trying to run a very simple Redis client on Mono in Mac OS X with the following options:

var configOptions = new ConfigurationOptions() 
{
    EndPoints =
{
    { "localhost", 6379 },
},
ResolveDns = true,
KeepAlive = 180
};
StringWriter sw = new StringWriter();
ConnectionMultiplexer.Connect(configOptions, tw);

It fails to connect. Here is the trace:

localhost:6379,keepAlive=180,resolveDns=True

Using DNS to resolve 'localhost'...
'localhost' => 127.0.0.1
1 unique nodes specified
Requesting tie-break from 127.0.0.1:6379 > __Booksleeve_TieBreak...
Allowing endpoints 00:00:01 to respond...
127.0.0.1:6379 faulted: UnableToResolvePhysicalConnection on PING
127.0.0.1:6379 failed to nominate (Faulted)
> UnableToResolvePhysicalConnection on GET
No masters detected
127.0.0.1:6379: Standalone v2.0.0, master; keep-alive: 00:03:00; int: Connecting; sub: Connecting; not in use: DidNotRespond
127.0.0.1:6379: int ops=0, qu=0, qs=0, qc=1, wr=0, async=1, socks=2; sub ops=0, qu=0, qs=0, qc=0, wr=0, socks=1
Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0 (0.00 ops/s; spans 10s)
Sync timeouts: 0; fire and forget: 0; last heartbeat: -1s ago
Starting heartbeat...

I've tried with and without ResolveDNS and specifying the IP address directly. Tried several ports as well. Server is running and is reachable by redis-cli.

StackExchange.Redis version="1.0.289" targetFramework="net45"

Redis-64 2.8.9

Update

StackExchange.Redis version="1.0.297" targetFramework="net45", same problem but different log

localhost:6666,keepAlive=180,resolveDns=True

Using DNS to resolve 'localhost'...
'localhost' => 127.0.0.1
1 unique nodes specified
Requesting tie-break from 127.0.0.1:6666 > __Booksleeve_TieBreak...
Allowing endpoints 00:00:05 to respond...
127.0.0.1:6666 faulted: UnableToResolvePhysicalConnection on PING
127.0.0.1:6666 failed to nominate (Faulted)
> UnableToResolvePhysicalConnection on GET
No masters detected
127.0.0.1:6666: Standalone v2.0.0, master; keep-alive: 00:03:00; int: Connecting; sub: Connecting; not in use: DidNotRespond
127.0.0.1:6666: int ops=0, qu=0, qs=0, qc=1, wr=0, async=1, socks=2; sub ops=0, qu=0, qs=0, qc=0, wr=0, socks=1
Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0 (0.00 ops/s; spans 10s)
Sync timeouts: 0; fire and forget: 0; last heartbeat: -1s ago
resetting failing connections to retry...
retrying; attempts left: 2...
1 unique nodes specified
Requesting tie-break from 127.0.0.1:6666 > __Booksleeve_TieBreak...
Allowing endpoints 00:00:05 to respond...
127.0.0.1:6666 returned, but incorrectly
127.0.0.1:6666 failed to nominate (Faulted)
> UnableToResolvePhysicalConnection on GET
No masters detected
127.0.0.1:6666: Standalone v2.0.0, master; keep-alive: 00:03:00; int: Disconnected; sub: Connecting; not in use: DidNotRespond
127.0.0.1:6666: int ops=0, qu=0, qs=0, qc=1, wr=0, async=5, socks=3; sub ops=0, qu=0, qs=0, qc=0, wr=0, socks=2
Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0 (0.00 ops/s; spans 10s)
Sync timeouts: 0; fire and forget: 0; last heartbeat: -1s ago
resetting failing connections to retry...
retrying; attempts left: 1...
1 unique nodes specified
Requesting tie-break from 127.0.0.1:6666 > __Booksleeve_TieBreak...
Allowing endpoints 00:00:05 to respond...
127.0.0.1:6666 returned, but incorrectly
127.0.0.1:6666 failed to nominate (Faulted)
> UnableToResolvePhysicalConnection on GET
No masters detected
127.0.0.1:6666: Standalone v2.0.0, master; keep-alive: 00:03:00; int: Disconnected; sub: Connecting; not in use: DidNotRespond
127.0.0.1:6666: int ops=0, qu=0, qs=0, qc=1, wr=0, async=8, socks=4; sub ops=0, qu=0, qs=0, qc=0, wr=0, socks=3
Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0 (0.00 ops/s; spans 10s)
Sync timeouts: 0; fire and forget: 0; last heartbeat: -1s ago

As others stated, StackExchange.Redis has problems connecting to the server on mono, and you have to build a custom assembly from the source, targeting Mono. So I created a nuget package from the mono build of the library using monobuild.bash . You can use it as a direct replacement for the original StackExchange.Redis on mono.

https://www.nuget.org/packages/StackExchange.Redis.Mono/

As we are using the package in our server application, I will be updating it regularly.

I had the same problem using the nuget package directly. I've cloned the StackExchange.Redis repo and created a new DLL with the included bash command for mono:

./monobuild.bash

Referenced the resulting DLL and it worked flawlessly on OSX with the exact code that you've placed on the question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM