gpt4 book ai didi

asp.net - 我应该多久打开/关闭一次 Booksleeve 连接?

转载 作者:IT王子 更新时间:2023-10-29 05:54:52 26 4
gpt4 key购买 nike

我在 C#/ASP.NET 4 应用程序中使用 Booksleeve 库。目前,RedisConnection 对象是我的 MonoLink 类中的静态对象。我应该保持这个连接打开,还是应该在每次查询/交易后打开/关闭它(就像我现在所做的那样)?只是有点迷糊。以下是我目前的使用方式:

public static MonoLink CreateMonolink(string URL)
{
redis.Open();
var transaction = redis.CreateTransaction();

string Key = null;

try
{
var IncrementTask = transaction.Strings.Increment(0, "nextmonolink");
if (!IncrementTask.Wait(5000))
{
transaction.Discard();
throw new System.TimeoutException("Monolink index increment timed out.");
}

// Increment complete
Key = string.Format("monolink:{0}", IncrementTask.Result);

var AddLinkTask = transaction.Strings.Set(0, Key, URL);
if (!AddLinkTask.Wait(5000))
{
transaction.Discard();
throw new System.TimeoutException("Add monolink creation timed out.");
}

// Run the transaction
var ExecTransaction = transaction.Execute();
if (!ExecTransaction.Wait(5000))
{
throw new System.TimeoutException("Add monolink transaction timed out.");
}
}
catch (Exception ex)
{
transaction.Discard();
throw ex;
}
finally
{
redis.Close(false);
}

// Link has been added to redis
MonoLink ml = new MonoLink();
ml.Key = Key;
ml.URL = URL;

return ml;
}

提前感谢您的任何回复/见解。另外,这个库有任何官方文档吗?谢谢你这么。 ^_^.

最佳答案

According to author of Booksleeve ,

The connection is thread safe and intended to be massively shared; don't do a connection per operation.

关于asp.net - 我应该多久打开/关闭一次 Booksleeve 连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7543751/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com