如何格式化ServiceStack Redis连接字符串

问题描述 投票:0回答:1

如何格式化以下 Redis 连接字符串:

连接字符串: myIP,keepAlive=180,ConnectRetry=30,ConnectTimeout=5000

我开始编写单元测试,但不断收到输入字符串格式不正确的错误消息

 [TestFixtureSetUp]
        private void Init()
        {
            var redisConnectionString = "myIP,keepAlive=180,ConnectRetry=30,ConnectTimeout=5000";                
         _clientsManager = new PooledRedisClientManager(redisConnectionString);

        }

        [Test]
        public void CanConnectToRedis()
        {
            var readWrite = (RedisClient) _clientsManager.GetClient();
            using (var redis = _clientsManager.GetClient())
            {
                var redisClient = redis;

            }
        }
redis servicestack.redis
1个回答
12
投票

连接字符串格式参见ServiceStack.Redis主页

redis://localhost:6379?ConnectTimeout=5000&IdleTimeOutSecs=180

可以在任何 Redis 客户端管理器中使用

var redisManager = new RedisManagerPool(
    "redis://localhost:6379?ConnectTimeout=5000&IdleTimeOutSecs=180");
using (var client = redisManager.GetClient())
{
    client.Info.PrintDump();
}

主页上还列出了可用配置选项列表

© www.soinside.com 2019 - 2024. All rights reserved.