protected RedisSubBase(RedisDb redisDb, RedisSubKey key, TimeSpan?subscribeTimeout = null) { RedisDb = redisDb; Key = key.Key; PatternMode = key.PatternMode; FullKey = RedisDb.FullKey(Key); Subscriber = RedisDb.Redis.GetSubscriber(); RedisChannel = new RedisChannel(FullKey, PatternMode); _onMessage = OnMessage; _subscribeTimeoutCts = new CancellationTokenSource(subscribeTimeout ?? DefaultSubscribeTimeout); WhenSubscribed = Task.Run(async() => { var cancellationToken = _subscribeTimeoutCts.Token; try { await Subscriber .SubscribeAsync(RedisChannel, _onMessage) .WithFakeCancellation(cancellationToken) .ConfigureAwait(false); } catch (OperationCanceledException) { if (IsDisposeStarted) { throw; } if (cancellationToken.IsCancellationRequested) { throw new TimeoutException(); } throw; } }, CancellationToken.None); }
public RedisPub(RedisDb redisDb, string key) { RedisDb = redisDb; Key = key; FullKey = RedisDb.FullKey(Key); Subscriber = RedisDb.Redis.GetSubscriber(); }