Han*_*ney 13 c# redis booksleeve stackexchange.redis
我StackExchange.Redis用来与3个不同的Redis实例通信:1个在同一个子网上,2个在远程.这是我的配置代码:
var configurationOptions = new ConfigurationOptions
{
EndPoints =
{
{ host, port }
},
KeepAlive = 180,
Password = password,
DefaultVersion = new Version("2.8.5"),
// Needed for cache clear
AllowAdmin = true
};
var connectionMultiplexer = ConnectionMultiplexer.Connect(configurationOptions );
Run Code Online (Sandbox Code Playgroud)
最后一行大约70%的时间抛出连接异常:
无法连接到redis服务器; 要创建断开连接的多路复用器,请禁用AbortOnConnectFail
为什么这是间歇性的和/或我做错了什么?当我在命令提示符下ping Redis服务器时,丢包率为0%,响应时间<1 ms.网络稳定.
谢谢!
编辑
以下是失败时日志输出的内容:
10.48.68.28:6379,keepAlive=180,version=2.8.5
1 unique nodes specified
Requesting tie-break from 10.48.68.28:6379 > __Booksleeve_TieBreak...
Allowing endpoints 00:00:01 to respond...
10.48.68.28:6379 did not respond
10.48.68.28:6379 failed to nominate (WaitingForActivation)
No masters detected
10.48.68.28:6379: Standalone v2.8.5, master; keep-alive: 00:03:00; int: Connecting; sub: ConnectedEstablished, 1 active; not in use: DidNotRespond
10.48.68.28:6379: int ops=0, qu=4, qs=0, qc=0, wr=0, socks=1; sub ops=2, qu=0, qs=0, qc=0, wr=0, subs=1, sync=2, socks=1
Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0+2=2 (0.20 ops/s; spans 10s)
Sync timeouts: 0; fire and forget: 0; last heartbeat: -1s ago
Starting heartbeat...
Run Code Online (Sandbox Code Playgroud)
小智 7
通过在连接到Redis时为客户端设置ConnectTimeout,我能够解决它.这是我的代码
ConnectionMultiplexer connection =
ConnectionMultiplexer.Connect("endpoint,password=password,ConnectTimeout=10000");
Run Code Online (Sandbox Code Playgroud)
小智 5
这似乎是一个常见的问题:https://github.com/StackExchange/StackExchange.Redis/issues/42
我刚刚下载了新版本,并没有再次看到问题.然而.
您收到的错误通常表明您尚未abortConnect=false在连接字符串中设置。默认值为abortConnect,true这使得StackExchange.Redis在某些情况下不会自动重新连接到服务器。我们强烈建议您设置abortConnect=false连接字符串,以便在发生网络故障时 Redis 能够在后台自动重新连接。
来源:https ://stackoverflow.com/a/30918632/2236811
所以我的init()看起来像这样
ConfigurationOptions co = new ConfigurationOptions()
{
SyncTimeout = 500000,
EndPoints =
{
{url,portNumber }
},
AbortOnConnectFail = false // this prevents that error
};
seClient = ConnectionMultiplexer.Connect(co);
Run Code Online (Sandbox Code Playgroud)
谢谢
| 归档时间: |
|
| 查看次数: |
31266 次 |
| 最近记录: |