Ejemplo n.º 1
0
        private static void HandleIncrement(RedisChannel channelName, RedisValue rawJson)
        {
            var cmd = IncrementCommand.Parse(rawJson);

            log.Information("Received increment command for {0} (amount = {1}) sourced by {2}", cmd.Emoji, cmd.Amount,
                            cmd.SourceType);
            IncrementQueue.Add(cmd);
        }
Ejemplo n.º 2
0
        public static void Begin(string host, int port)
        {
            _redis = ConnectionMultiplexer.Connect($"{host}:{port}");
            _redis.GetSubscriber().Subscribe(EmojiChannel.IncrementCommands, (chan, rawJson) =>
            {
                var command = IncrementCommand.Parse(rawJson);
                EmojiCache.HandleIncrement(command);
            });

            // Populate the cache with all known emoji
            var db = _redis.GetDatabase();

            foreach (var emoji in EmojiData.KnownSymbols)
            {
                var  countStr = db.StringGet(emoji);
                long count    = string.IsNullOrWhiteSpace(countStr) ? 0 : long.Parse(countStr);
                EmojiCache.SetValue(emoji, count);
            }
        }