ServiceStack.Redis 使用链接池方法

PooledRedisClientManager

1、RedisManage.cs

public static class RedisManager
{
  private static PooledRedisClientManager _prcm;

  static RedisManager()
  {
      CreateManager();
  }

    /// 
    /// 创建链接池管理对象
    /// 
  private static void CreateManager()
  {   
      _prcm = new PooledRedisClientManager(writeServerList, readServerList,
                  new RedisClientManagerConfig
                  {
                      /*Config*/
                  });
  }
  public static IRedisClient GetClient()
  {
      if (_prcm == null)
      {
          CreateManager();
      }
      return _prcm.GetClient();
  }

  public static IRedisClient GetReadOnlyClient()
  {
      if (_prcm == null)
      {
          CreateManager();
      }
      return _prcm.GetReadOnlyClient();
  }
}

2、调用

using(var client = RedisManage.GetClient())
{
  /*content*/
}

using(var client = RedisManage.GetReadOnlyClient())
{
  /*content*/
}

转载于:https://www.cnblogs.com/ArvinZhao/p/6088209.html

你可能感兴趣的:(ServiceStack.Redis 使用链接池方法)