[英]No connection is available to service this operation - Redis with StackExchange.Redis
[英]StackExchange.Redis: No connection is available to service this operation. UnableToConnect on HOST:PORT/Interactive
我正在嘗試從 C# 連接 REDIS 數據庫(GCP-memorystore-Redis)。 在將值設置為 Redis 時,我收到如下異常:
沒有連接可用於服務此操作。 UnableToConnect on 10.0.0.2 : 6379 / Interactive , Initializing, last: NONE, origin: BeginConnectAsync,outstanding: 0, last-read: 10s ago, last-write: 10s ago, unanswer-write: 115s ago, keep-alive: 180s , state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 0s ago, v: 2.0.519.65453 ; IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=1,Free=32766,Min=1,Max=32767), Local-CPU: n/a
我使用StackExchange.Redis版本:2.0.519
代碼:
IDatabase redisDB;
try {
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect($"{host}:{port},resolvedns=1,abortConnect=False,keepAlive=180,connectTimeout=10000");
redisDB = redis.GetDatabase();
if(redisDB==null)
{
**//Getting Error**
var messageId = redisDB.StreamAdd("event_stream", "foo_name", "bar_value");
//redisDB.StringSet("RedisKey", "RedisValue");
}
}
(或)我也試圖通過使用下面的代碼來設置值。 (遇到同樣的問題)
redisDB.StringSet("RedisKey", "RedisValue");
你能幫忙解決這個問題嗎?
ConnectionMultiplexer connectionstring 中的變量“host”似乎不正確。 查看您的異常“IPAddress:6379/Interactive 上的 UnableToConnect”。 所以你的變量“端口”是正確的,它的值為 6379。也許你將“主機”變量轉換為字符串是錯誤的。 所以你有變量類型(IPAddress)而不是實際值。
看起來這可能主要是格式/連接問題,在這種情況下,最簡單的方法是:不要這樣做。 有一個強類型對象模型,它很難出錯:
var config = new ConfigurationOptions {
EndPoints = {
new DnsEndPoint(host, port),
// new IPEndPoint(host, port), // <== or this if 'host' is an IPAddress
},
ResolveDns = true,
AbortOnConnectFail = false,
KeepAlive = 180,
ConnectTimeout = 10000,
};
var muxer = ConnectionMultiplexer.Connect(config);
在內部,如果你給它一個string
,它要做的第一件事就是解析string
以創建上面的內容,所以你不妨直接去!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.