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

Commit 7d87c16

Browse files
committed
Add example of MasterFailoverWithPassword
1 parent 281722f commit 7d87c16

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

tests/Console.Tests/Console.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<ItemGroup>
6363
<Compile Include="BlockingPop.cs" />
6464
<Compile Include="ForceFailover.cs" />
65+
<Compile Include="MasterFailoverWithPassword.cs" />
6566
<Compile Include="NetworkRedisSentinelFailoverTests.cs" />
6667
<Compile Include="GoogleRedisSentinelFailoverTests.cs" />
6768
<Compile Include="HashCollectionStressTests.cs" />
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Threading;
3+
using ServiceStack;
4+
using ServiceStack.Redis;
5+
6+
namespace ConsoleTests
7+
{
8+
public class MasterFailoverWithPassword
9+
{
10+
public void Execute()
11+
{
12+
var sentinelHosts = new[] { "127.0.0.1:26380", "127.0.0.1:26381", "127.0.0.1:26382" };
13+
var sentinel = new RedisSentinel(sentinelHosts, masterName: "mymaster");
14+
sentinel.HostFilter = host => "password@{0}".Fmt(host);
15+
var manager = sentinel.Start();
16+
17+
sentinel.OnWorkerError = exception => Console.WriteLine(exception);
18+
19+
while (true)
20+
{
21+
try
22+
{
23+
const string RedisKey = "my Name";
24+
using (var client = manager.GetClient())
25+
{
26+
var result = client.Get<string>(RedisKey);
27+
Console.WriteLine("Redis Key: {0} \t Port: {1}", result, client.Port);
28+
}
29+
}
30+
catch (Exception ex)
31+
{
32+
Console.WriteLine($"Error {ex.Message}");
33+
}
34+
Thread.Sleep(3000);
35+
}
36+
}
37+
}
38+
}

tests/Console.Tests/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ static void Main(string[] args)
3434

3535
//new ForceFailover().Execute();
3636

37-
new BlockingPop().Execute();
37+
//new BlockingPop().Execute();
38+
39+
new MasterFailoverWithPassword().Execute();
3840
}
3941
}
4042
}

0 commit comments

Comments
 (0)