我在 VS2010 中的 Booksleeve 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);
Transactions 我也有同样的问题,但我觉得它源于同一个问题。我需要检索值,然后排队另一个命令的原因是因为我以后对 Redis 的操作是根据我返回的值来确定的!