public async Task SubscribeAsync(string channel, Action <string, string> handler) { if (_redis.Connection == null) { await _redis.ConnectAsync(); } try { var subscriber = _redis.Connection.GetSubscriber(); await subscriber.SubscribeAsync(_channelPrefix + channel, (redisChannel, redisValue) => { var tokens = redisValue.ToString().Split('/').ToArray(); if (tokens.Length != 2 || tokens[0].Length == 0 || tokens[0].Equals(_hostName, StringComparison.OrdinalIgnoreCase)) { return; } handler(channel, tokens[1]); }); } catch (Exception e) { _logger.LogError(e, "'Unable to subscribe to the channel {ChannelName}'.", _channelPrefix + channel); } }
public async Task TagAsync(string key, params string[] tags) { if (_redis.Database == null) { await _redis.ConnectAsync(); if (_redis.Database == null) { _logger.LogError("Fails to add the '{KeyName}' to the {PrefixName} tags.", key, _prefix); return; } } try { foreach (var tag in tags) { await _redis.Database.SetAddAsync(_prefix + tag, key); } } catch (Exception e) { _logger.LogError(e, "Fails to add the '{KeyName}' to the {PrefixName} tags.", key, _prefix); } }
public async Task TagAsync(string key, params string[] tags) { if (_redis.Database == null) { await _redis.ConnectAsync(); } foreach (var tag in tags) { await _redis.Database.SetAddAsync(_prefix + tag, key); } }