public void Subscribe(string subscriptionType, List <string> channelParams, IRedisCallbackBL bl, int?databaseId = null) { string dbId = databaseId.HasValue ? databaseId.Value.ToString() : "*"; var subscriber = _redisConnection.GetSubscriber(); subscriber.Subscribe($"__{subscriptionType}@{dbId}__:*", (channel, value) => { foreach (string param in channelParams) { Regex regex = new Regex($"__{subscriptionType}@(\\d)__:{param}"); var match = regex.Match(channel); if (!match.Success) { break; } int.TryParse(match.Groups[1].Value, out int sourceDatabaseId); try { if ((string)channel == $"__{subscriptionType}@{sourceDatabaseId}__:{param}") { bl.KeyEventHandler(param, value, sourceDatabaseId); } } catch (Exception ex) { } } }); }
private void Subscribe(string subscriptionType, string channelParam, IRedisCallbackBL bl) { _subscriber.Subscribe($"__{subscriptionType}@{Configuration.DatabaseId}__:{channelParam}", (channel, value) => { Task.Run(() => bl.HandleEvent(channelParam, value)) .ContinueWith(task => { if (task.IsFaulted) { //TODO: write a log for error } }) .ConfigureAwait(false); }); }
public void SubscribeToKeyEventNotifications(RedisEventType eventType, IRedisCallbackBL bl) { Subscribe(SubscriptionType.Keyspace, eventType.ToString(), bl); }
public void SubscribeToKeySpaceNotifications(string key, IRedisCallbackBL bl) { Subscribe(SubscriptionType.Keyevent, key, bl); }