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

Commit d0bd39b

Browse files
committed
Add ChannelsMatching support to RedisPubServer for subscribing to channel patterns
Add IsSentinelSubscription to avoid calling unknown operations on Sentinel hosts like TIME
1 parent 898d940 commit d0bd39b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/ServiceStack.Redis/RedisPubSubServer.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Text;
44
using System.Threading;
55
using ServiceStack.Logging;
6-
using ServiceStack.Text;
76

87
namespace ServiceStack.Redis
98
{
@@ -29,6 +28,7 @@ public class RedisPubSubServer : IRedisPubSubServer
2928
public Action<string> OnUnSubscribe { get; set; }
3029
public Action<Exception> OnError { get; set; }
3130
public Action<IRedisPubSubServer> OnFailover { get; set; }
31+
public bool IsSentinelSubscription { get; set; }
3232

3333
readonly Random rand = new Random(Environment.TickCount);
3434

@@ -62,8 +62,10 @@ public long BgThreadCount
6262
get { return Interlocked.CompareExchange(ref bgThreadCount, 0, 0); }
6363
}
6464

65+
public const string AllChannelsWildCard = "*";
6566
public IRedisClientsManager ClientsManager { get; set; }
6667
public string[] Channels { get; set; }
68+
public string[] ChannelsMatching { get; set; }
6769
public TimeSpan? WaitBeforeNextRestart { get; set; }
6870

6971
public RedisPubSubServer(IRedisClientsManager clientsManager, params string[] channels)
@@ -141,7 +143,9 @@ private void Init()
141143
using (var redis = ClientsManager.GetReadOnlyClient())
142144
{
143145
startedAt = Stopwatch.StartNew();
144-
serverTimeAtStart = redis.GetServerTime();
146+
serverTimeAtStart = IsSentinelSubscription
147+
? DateTime.UtcNow
148+
: redis.GetServerTime();
145149
}
146150
}
147151
catch (Exception ex)
@@ -281,7 +285,12 @@ private void RunLoop()
281285
}
282286
};
283287

284-
subscription.SubscribeToChannels(Channels); //blocks thread
288+
//blocks thread
289+
if (ChannelsMatching != null)
290+
subscription.SubscribeToChannelsMatching(ChannelsMatching);
291+
else
292+
subscription.SubscribeToChannels(Channels);
293+
285294
masterClient = null;
286295
}
287296
}

0 commit comments

Comments
 (0)