我应该多久打开/关闭我的Booksleeve连接? [英] How often should I open/close my Booksleeve connection?

查看:199
本文介绍了我应该多久打开/关闭我的Booksleeve连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Booksleeve库在C#/ ASP.NET 4应用程序。目前RedisConnection对象是在我的MonoLink类的静态对象。我应该保持此连接打开,或者我应该是打开/每次查询/交易后关闭它(因为我现在做)?只要稍微混淆。下面是我如何使用它,截至目前:

 公共静态MonoLink CreateMonolink(字符串URL)
{
    redis.Open();
    变种事务= redis.CreateTransaction();    字符串键= NULL;    尝试
    {
        变种IncrementTask = transaction.Strings.Increment(0,nextmonolink);
        如果(!IncrementTask.Wait(5000))
        {
            transaction.Discard();
            抛出新System.TimeoutException(Monolink指数增量超时。);
        }        //增量完整
        键=的String.Format(monolink:{0},IncrementTask.Result);        VAR AddLinkTask = transaction.Strings.Set(0,钥匙,URL);
        如果(!AddLinkTask.Wait(5000))
        {
            transaction.Discard();
            抛出新System.TimeoutException(添加monolink创建超时。);
        }        //运行事务
        变种ExecTransaction = transaction.Execute();
        如果(!ExecTransaction.Wait(5000))
        {
            抛出新System.TimeoutException(添加monolink交易超时。);
        }
    }
    赶上(异常前)
    {
        transaction.Discard();
        扔恩;
    }
    最后
    {
        redis.Close(假);
    }    //链接已经被添加到Redis的
    MonoLink毫升=新MonoLink();
    ml.Key =键;
    ml.URL = URL;    返回毫升;
}

谢谢,提前,对于任何反应/洞察力。此外,有没有为这个图书馆任何形式的正式文件?谢谢你这么。 ^ _ ^


解决方案

  

我应该保持此连接打开,或者我应该是打开/关闭
  它每次查询/交易后(如我现在这样)?


有可能是一个小的开销,如果你将打开一个新的连接,你想查询/交易,每次虽然Redis是专为高级别并发连接的客户端,可能存在的性能问题,如果他们的人数大约是几十十万。据我所知,连接池应该由客户端库来完成(因为Redis的本身不具备此功能),所以你应该检查是否booksleeve的支持这个东西。否则,你应该打开连接当你的应用程序启动并保持打开它的生命周期(如果你不需要客户端并联连接的Redis出于某种原因)。


  

此外,有没有为这个图书馆?

任何形式的正式文件

我能找到关于如何使用它的唯一文档是测试在它的文件夹源$ C ​​$ CS。

I'm using the Booksleeve library in a C#/ASP.NET 4 application. Currently the RedisConnection object is a static object across my MonoLink class. Should I be keeping this connection open, or should I be open/closing it after each query/transaction (as I'm doing now)? Just slightly confused. Here's how I'm using it, as of now:

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;
}

Thanks, in advance, for any responses/insight. Also, is there any sort of official documentation for this library? Thank you S.O. ^_^.

解决方案

Should I be keeping this connection open, or should I be open/closing it after each query/transaction (as I'm doing now)?

There is probably a little overhead if you will open a new connection each time you want to make a query/transaction and although redis is designed for high level of concurrently connected clients, there might be performance problems if their number is around tens of thousands. As far as I know connection pooling should be done by the client libraries (because redis itself doesn't have this functionality), so you should check if booksleeve supports this stuff. Otherwise you should open the connection when your application starts and keep it open for it's lifetime (in case you don't need parallel clients connected to redis for some reason).

Also, is there any sort of official documentation for this library?

The only documentation I was able to find regarding how to use it was tests folder in it's source codes.

这篇关于我应该多久打开/关闭我的Booksleeve连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆