Exemple #1
0
        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)
                    {
                    }
                }
            });
        }
Exemple #2
0
 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);
     });
 }
Exemple #3
0
 public void SubscribeToKeyEventNotifications(RedisEventType eventType, IRedisCallbackBL bl)
 {
     Subscribe(SubscriptionType.Keyspace, eventType.ToString(), bl);
 }
Exemple #4
0
 public void SubscribeToKeySpaceNotifications(string key, IRedisCallbackBL bl)
 {
     Subscribe(SubscriptionType.Keyevent, key, bl);
 }