Example #1
0
        public static void CreateConfiguredKeys()
        {
            var redis       = ConnectionManagement.GetInstance();
            var keysCreated = redis.GetKey <bool>(BenchmarkDotNetKeysCreated);

            if (keysCreated)
            {
                return;
            }

            Console.WriteLine("Creating keys to execute the \"GET\" benchmarks:");

            var amountOfKeys = BenchmarkSettings.AmountOfKeys;

            using (var progress = new ProgressBar(amountOfKeys, $"Creating {amountOfKeys} keys..."))
            {
                for (var i = 0; i <= amountOfKeys; i++)
                {
                    var keyName = string.Format(KeyPrefix, i);
                    try
                    {
                        redis.CreateKey(keyName, BenchmarkSettings.KeyDataContent);
                    }
                    catch (Exception ex)
                    {
                        progress.WriteLine($"Failed to key {keyName} creation: {ex}");
                    }
                    progress.Tick(i == amountOfKeys ? "Done!" : $"Creating {i} of {amountOfKeys} key(s)...");
                }
            }
            redis.CreateKey(BenchmarkDotNetKeysCreated, true, TimeSpan.FromSeconds(28800));
            Console.WriteLine($"{BenchmarkSettings.AmountOfKeys} key(s) created.");
        }
Example #2
0
 public static ConnectionManagement GetInstance(string connectionString = null)
 {
     if (_instance == null && !string.IsNullOrWhiteSpace(connectionString))
     {
         lock (SyncRoot)
         {
             if (_instance == null)
             {
                 _instance = new ConnectionManagement();
                 _instance.CreateRedisConnection(connectionString);
             }
         }
     }
     return(_instance);
 }
Example #3
0
        public static void Initialize()
        {
            var assemblyDirectory = AssemblyDirectory;

            var config = new ConfigurationBuilder()
                         .SetBasePath(assemblyDirectory)
                         .AddJsonFile("appsettings.json", true, true)
                         .Build();

            var services = new ServiceCollection();

            services.AddSingleton(config);
            services.AddSingleton <RedisSettings>();
            services.AddSingleton <BenchmarkSettings>();

            var provider = services.BuildServiceProvider();

            BenchmarkSettings = provider.GetService <BenchmarkSettings>();
            var redisSettings = provider.GetService <RedisSettings>();

            ConnectionManagement = ConnectionManagement.GetInstance(redisSettings.ConnectionString);
        }