예제 #1
0
        public static void GetLeaderScore(string host, int port, string password, int count, int sleep)
        {
            RedisUtils redisUtils = new RedisUtils(host, port, password);

            using (IRedisNativeClient client = redisUtils.GetNativeClient())
            {
                var counter = 1;
                if (count < 1)
                {
                    while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
                    {
                        counter = 1;
                        Common.DashLine();
                        Console.WriteLine($"Infinite Loop (3 seconds)");
                        Console.WriteLine($"Leaderboard - {DateTime.Now}");
                        Common.DashLine();

                        var timer1 = System.Diagnostics.Stopwatch.StartNew();
                        IDictionary <string, double> dic1 = redisUtils.GetClient().GetAllWithScoresFromSortedSet("leaderboard");

                        // Iterate through the Dictionary and Print Key, Value Pair
                        foreach (KeyValuePair <string, double> c in dic1.OrderByDescending(key => key.Value).Take(10))
                        {
                            var val1 = Convert.ToString(c.Key);
                            var val2 = Convert.ToString(c.Value);
                            Console.WriteLine($" {Convert.ToString(counter).PadRight(3)} {val1.PadRight(10)} {val2}");
                            counter++;
                        }

                        Common.DashLine();
                        Console.WriteLine($"Elapsed Time .. {Math.Round(timer1.Elapsed.TotalSeconds, 3)} sec.");
                        Console.WriteLine("Press ESC Key to Exit Loop\n");
                        Thread.Sleep(sleep);
                    }
                }
                else
                {
                    Common.DashLine();
                    Console.WriteLine($"One-Time Update");
                    Console.WriteLine($"Leaderboard - {DateTime.Now}");
                    Common.DashLine();
                    var timer1 = System.Diagnostics.Stopwatch.StartNew();
                    IDictionary <string, double> dic1 = redisUtils.GetClient().GetAllWithScoresFromSortedSet("leaderboard");
                    foreach (KeyValuePair <string, double> c in dic1.OrderByDescending(key => key.Value).Take(10))
                    {
                        var val1 = Convert.ToString(c.Key);
                        var val2 = Convert.ToString(c.Value);
                        Console.WriteLine($" {Convert.ToString(counter).PadRight(3)} {val1.PadRight(10)} {val2}");
                        counter++;
                    }
                    Common.DashLine();
                    Console.WriteLine($"Elapsed Time .. {Math.Round(timer1.Elapsed.TotalSeconds, 3)} sec.");
                } // end If - While - Else Loop
            }     // end using IRedisNativeClient
        }         // end GetLeaderScore
예제 #2
0
        /// <summary>
        /// Generate Seed Data for Local C# testing
        /// Note: All Values are set to 0.0 initially
        /// </summary>
        /// <param name="host">Hostname of the server, set by Appconfig</param>
        /// <param name="port">Redis port, set by AppConfig</param>
        /// <param name="password">server password, set by AppConfig</param>
        public static void AddItemsToSet(string host, int port, string password)
        {
            RedisUtils redisUtils = new RedisUtils(host, port, password);

            // Use Pipeline to insert records into Redis
            using (var pipeline = redisUtils.GetClient().CreatePipeline())
            {
                var    timer1 = System.Diagnostics.Stopwatch.StartNew();
                int    d      = 1;
                string value;
                string seedfile = SeedFile;

                //string source_list = ConfigurationManager.AppSettings["SourceList"];
                List <string> tempList = File.ReadLines(seedfile).ToList();

                // Count the number of items in the sorted set
                int c = tempList.Count;

                var timer2 = System.Diagnostics.Stopwatch.StartNew();
                Console.Write("* R => AddItemToSortedSet(*)\n");
                foreach (var item in tempList)
                {
                    value = timer1.ElapsedTicks.ToString();
                    Console.Write($"\r* Adding Keys .......: [ {d.ToString("N0")} ] ");
                    pipeline.QueueCommand(r => r.AddItemToSortedSet("leaderboard", item, 0));
                    d++;
                }
                pipeline.Flush();

                timer1.Stop();
                var elapsedMs = timer1.ElapsedMilliseconds;
                Console.WriteLine($"\n* Pipelined Keys ....: [ {c.ToString("N0")} ]");
                Console.WriteLine($"* Update Time .......: [ {Math.Round(timer2.Elapsed.TotalSeconds, 5)} ] sec.");
            }
        }
예제 #3
0
        /// <summary>
        /// Update Seed Data for Local C# testing ** NOT FOR PRODUCTION **
        /// </summary>
        /// <param name="host">Hostname of the server, set by Appconfig</param>
        /// <param name="port">Redis port, set by AppConfig</param>
        /// <param name="password">server password, set by AppConfig</param>
        public static void IncrementSortedSet(string host, int port, string password)
        {
            RedisUtils redisUtils = new RedisUtils(host, port, password);

            using (IRedisClient client = redisUtils.GetClient())
            {
                using (var pipeline = redisUtils.GetClient().CreatePipeline())
                {
                    // proces variables
                    var    timer1 = System.Diagnostics.Stopwatch.StartNew();
                    int    d      = 1;
                    string t2;
                    string value;
                    string seedFile = SeedFile;

                    // create the see list from source list file
                    // string source_list = ConfigurationManager.AppSettings["SourceList"];
                    List <string> callsigns = File.ReadLines(seedFile).ToList();

                    // Count the number of items in the sorted set
                    int c = callsigns.Count;

                    // start update loop
                    var timer2 = System.Diagnostics.Stopwatch.StartNew(); // This is the Redis update time portion
                    Console.Write("* R => IncrementItemInSortedSet(*)\n");
                    Console.WriteLine($"* Seed File Count ..: [ {c.ToString("N0")} ]");
                    foreach (var item in callsigns)
                    {
                        value = timer1.ElapsedTicks.ToString();
                        t2    = value.Substring(value.Length - 3); // 3 gets the last three digits ot ET in miliseconds
                        Console.Write($"\r* Updating Keys ....: [ {d.ToString("N0")} ] ");
                        pipeline.QueueCommand(r => r.IncrementItemInSortedSet("leaderboard", item, Convert.ToDouble(t2)));
                        d++;
                    }
                    pipeline.Flush(); // push the increments to Redis
                    timer1.Stop();    // stop the update timer
                    var elapsedMs = timer1.ElapsedMilliseconds;
                    Console.WriteLine($"\n* Pushed Keys ......: [ {c.ToString("N0")} ]");
                    Console.WriteLine($"* Update Time ......: [ {Math.Round(timer2.Elapsed.TotalSeconds, 5)} ]");
                } // END - Using Pipeline
            }     // END - IRedisClient
        }         // END - IncrementSortedSet
예제 #4
0
        public static void FlushDatabase(string host, int port, string password)
        {
            RedisUtils redisUtils = new RedisUtils(host, port, password);

            using (IRedisClient client = redisUtils.GetClient())
            {
                Console.WriteLine($"Flushing Database");
                Common.DashLine();
                client.FlushDb();
                Console.WriteLine($"Finished");
            }
        }