예제 #1
0
        static void Main()
        {
            RedisStore instance = RedisStore.getInstance();
            IDatabase  db       = instance.RedisCacheTable;
            var        sub      = db.Multiplexer.GetSubscriber();

            sub.Subscribe(RATE_HINTS_CHANNEL, delegate
            {
                // process all messages in queue
                string msg = db.ListRightPop(RATE_QUEUE_NAME);
                while (msg != null)
                {
                    Console.WriteLine(msg);
                    UserDataCounter userDataCounter = JsonConvert.DeserializeObject <UserDataCounter>(msg);

                    double relation = userDataCounter.countSoglasn == 0 ?
                                      0 : (double)userDataCounter.countGlasn / userDataCounter.countSoglasn;
                    string message = GetStringifyUserDataRater(userDataCounter, relation);
                    var idDb       = (int)db.StringGet($"RANK_{userDataCounter.id}");

                    instance.RedisCache(idDb).StringSet($"RANK_{userDataCounter.id}", message);

                    msg = db.ListRightPop(RATE_QUEUE_NAME);

                    Console.WriteLine(GetStringifyTextStatisticConsRater(userDataCounter.id, relation));

                    sub.Publish(EVENTS, GetStringifyTextStatisticConsRater(userDataCounter.id, relation));
                }
            });
            Console.WriteLine("Observable subscribe vowel cons rater is ready. For exit press Enter.");
            Console.ReadLine();
        }
예제 #2
0
        private static string GetStringifyUserDataRater(UserDataCounter userDataCounter, double relation)
        {
            UserDataRater userDataRater = new UserDataRater
            {
                id       = userDataCounter.id,
                region   = userDataCounter.region,
                message  = userDataCounter.message,
                relation = relation
            };

            return(JsonConvert.SerializeObject(userDataRater));
        }