Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 869cfc1

Browse files
committed
Add Can_specify_db_on_RedisSentinel() test
1 parent 76e22e0 commit 869cfc1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/ServiceStack.Redis/RedisSentinelWorker.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ public RedisSentinelWorker(RedisSentinel redisSentinel, string host, string sent
2626
this.redisSentinel = redisSentinel;
2727
this.redisManager = redisSentinel.redisManager;
2828
this.sentinelName = sentinelName;
29-
this.sentinelClient = new RedisClient(host);
30-
this.sentinelPubSubClient = new RedisClient(host);
29+
30+
//Sentinel Servers doesn't support DB, reset to 0
31+
this.sentinelClient = new RedisClient(host) { Db = 0 };
32+
this.sentinelPubSubClient = new RedisClient(host) { Db = 0 };
3133
this.sentinelSubscription = this.sentinelPubSubClient.CreateSubscription();
3234
this.sentinelSubscription.OnMessage = SentinelMessageReceived;
3335

tests/ServiceStack.Redis.Tests/RedisSentinelTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,24 @@ public void Can_specify_Timeout_on_RedisManager()
9797
Assert.That(((RedisNativeClient)client).IdleTimeOutSecs, Is.EqualTo(20));
9898
}
9999
}
100+
101+
[Test]
102+
public void Can_specify_db_on_RedisSentinel()
103+
{
104+
var host = new[] {"{0}:{1}".Fmt(TestConfig.SentinelHost, TestConfig.RedisSentinelPort)};
105+
var sentinel = new RedisSentinel(host, TestConfig.MasterName) {
106+
RedisManagerFactory =
107+
{
108+
FactoryFn = (writeHosts, readHosts) =>
109+
new PooledRedisClientManager(writeHosts, readHosts, initalDb:1)
110+
}
111+
};
112+
113+
using (var clientsManager = sentinel.Setup())
114+
using (var client = clientsManager.GetClient())
115+
{
116+
Assert.That(client.Db, Is.EqualTo(1));
117+
}
118+
}
100119
}
101120
}

0 commit comments

Comments
 (0)