[英]LARGE xml datasets - Reading from remote API, connection closing prematurely
[英]Booksleeve closing connection prematurely?
我在VS2010中使用Bookleeve的1.1.0.5版本遇到了困難,我打算如何使用它。 發生的是在執行並等待操作之后,Booksleeve有時會使連接保持關閉狀態,因此操作在下游會引發異常。
我遇到的最簡單的問題是:
static void Main(string[] args)
{
Func<RedisConnection> getNewRedisConnection = () =>
{
RedisConnection conn = new RedisConnection("Belasco");
conn.Error += (obj, eArgs) => { throw eArgs.Exception; };
return conn;
};
RedisConnection redisConn = null;
TaskScheduler.UnobservedTaskException += new EventHandler<UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException);
redisConn = getNewRedisConnection();
redisConn.Open();
var test1 = redisConn.Sets.GetAllString(0, "test1");
var testValues1 = test1.Result;
//var testValues1 = redisConn.Wait(test1);
var test2 = redisConn.Sets.GetAllString(0, "test2");
var testValues2 = test2.Result;
//var testValues2 = redisConn.Wait(test2);
redisConn.Close(false);
Console.WriteLine("Done");
Console.ReadKey();
}
static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
throw new NotImplementedException();
}
行var test2 = redisConn.Sets.GetAllString(0, "test2");
引發“隊列已關閉”異常。
現在,如果我關閉並重新打開請求之間的連接,似乎一切正常。
var test1 = redisConn.Sets.GetAllString(0, "test1");
var testValues1 = test1.Result;
//var testValues1 = redisConn.Wait(test1);
redisConn.Close(false);
redisConn = getNewRedisConnection();
redisConn.Open();
var test2 = redisConn.Sets.GetAllString(0, "test2");
var testValues2 = test2.Result;
//var testValues2 = redisConn.Wait(test2);
但是,如果執行“設置”操作,一切似乎都將恢復正常。
redisConn = getNewRedisConnection();
redisConn.Open();
var test0 = redisConn.Sets.Add(0, "test1", new string[] { "11", "22", "33", "44", "55" });
redisConn.Wait(test0);
redisConn.Close(false);
redisConn = getNewRedisConnection();
redisConn.Open();
var test1 = redisConn.Sets.GetAllString(0, "test1");
var testValues1 = test1.Result;
//var testValues1 = redisConn.Wait(test1);
redisConn.Close(false);
redisConn = getNewRedisConnection();
redisConn.Open();
var test2 = redisConn.Sets.GetAllString(0, "test2");
var testValues2 = test2.Result;
//var testValues2 = redisConn.Wait(test2);
我也有與交易相同的問題,但我覺得這是由同一問題引起的。 之所以需要檢索值,然后將另一個命令排隊,是因為我以后對Redis的操作是根據我得到的值確定的!
首先,不要在這里急切地關閉連接離子。 BookSleeve被設計為用作線程安全的多路復用器,可同時從任意數量的調用者處獲取負載。 打開連接會有開銷。 現在,有幾種方法可以關閉紅色連接:
我的猜測是服務器已配置了連接超時。 我不知道1.1。*,但是在某些時候添加了自動超時配置檢測和保持活動狀態的“ ping”消息,這很有幫助。 您可以通過redis-cli中的“ config get timeout”檢查超時。 如果這是問題所在,您可能會發現升級客戶端版本會有所幫助。 在某些構建中,您還可以手動指定超時配置(如果要否決服務器)。
對於意外的數據-不太可能,但是您可以掛鈎一些事件來檢測,記錄並對此做出反應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.