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

Commit e0c9c22

Browse files
committed
Add MultiBlockingRemoveAfterReconnection
1 parent 071b8fe commit e0c9c22

3 files changed

Lines changed: 76 additions & 1 deletion

File tree

tests/Console.Tests/Console.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<Compile Include="BrPopAfterReconnection.cs" />
8686
<Compile Include="ForceFailover.cs" />
8787
<Compile Include="MasterFailoverWithPassword.cs" />
88+
<Compile Include="MultiBlockingRemoveAfterReconnection.cs" />
8889
<Compile Include="NetworkRedisSentinelFailoverTests.cs" />
8990
<Compile Include="GoogleRedisSentinelFailoverTests.cs" />
9091
<Compile Include="HashCollectionStressTests.cs" />
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using ServiceStack.Logging;
5+
using ServiceStack.Redis;
6+
using ServiceStack.Text;
7+
8+
namespace ConsoleTests
9+
{
10+
public class MultiBlockingRemoveAfterReconnection
11+
{
12+
protected internal static RedisManagerPool RedisManager;
13+
14+
public void Execute()
15+
{
16+
// LogManager.LogFactory = new ConsoleLogFactory();
17+
// RedisConfig.EnableVerboseLogging = true;
18+
19+
RedisConfig.DefaultConnectTimeout = 20 * 1000;
20+
RedisConfig.DefaultRetryTimeout = 20 * 1000;
21+
22+
RedisManager = new RedisManagerPool($"localhost:6379?db=9");
23+
24+
MultipleBlocking(3);
25+
26+
Console.ReadLine();
27+
}
28+
29+
private static void MultipleBlocking(int count)
30+
{
31+
for (int i = 0; i < count; i++)
32+
{
33+
var queue = $"Q{i + 1}";
34+
RunTask(() => BlockingRemoveStartFromList(queue), $"Receive from {queue}");
35+
}
36+
}
37+
public static void BlockingRemoveStartFromList(string queue)
38+
{
39+
using (var client = RedisManager.GetClient() as RedisClient)
40+
{
41+
client.Ping();
42+
Console.WriteLine($"#{client.ClientId} Listening to {queue}");
43+
44+
var fromList = client.BlockingRemoveStartFromList(queue, TimeSpan.FromHours(10));
45+
Console.WriteLine($"#{client.ClientId} Received: '{fromList.Dump()}' from '{queue}'");
46+
}
47+
}
48+
49+
private static void RunTask(Action action, string name)
50+
{
51+
Task.Run(() =>
52+
{
53+
54+
while (true)
55+
{
56+
try
57+
{
58+
Console.WriteLine($"Invoking {name}");
59+
action.Invoke();
60+
}
61+
catch (Exception exception)
62+
{
63+
Console.WriteLine($"Exception in {name}: {exception}");
64+
//Thread.Sleep(5000);// Give redis some time to wake up!
65+
}
66+
67+
Thread.Sleep(100);
68+
}
69+
});
70+
}
71+
}
72+
}

tests/Console.Tests/Program.cs

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

3939
//new MasterFailoverWithPassword().Execute();
4040

41-
new BlockingRemoveAfterReconnection().Execute();
41+
//new BlockingRemoveAfterReconnection().Execute();
42+
43+
new MultiBlockingRemoveAfterReconnection().Execute();
4244
}
4345
}
4446
}

0 commit comments

Comments
 (0)