Exemple #1
0
 StringGet(
     RedisServiceSettingsViewModel serviceSettings,
     StringGetViewModel stringGetParameters,
     ExecutionSettingsViewModel executionSettings)
 {
     return(ExecuteRedisFunction(
                serviceSettings:    serviceSettings,
                redisFunction:      redisDb => redisDb.StringGet(
                    stringGetParameters.Key
                    ),
                executionSettings:  executionSettings
                ));
 }
Exemple #2
0
        ExecuteRedisFunction(
            RedisServiceSettingsViewModel serviceSettings,
            Action <IDatabase> redisFunction,
            ExecutionSettingsViewModel executionSettings)
        {
            try
            {
                var redisDb = GetRedisDb(serviceSettings);

                var totalStopWatch = Stopwatch.StartNew();

                Parallel.For(
                    fromInclusive:      0,
                    toExclusive:        executionSettings.NumberOfRepititions,
                    parallelOptions:    new ParallelOptions {
                    MaxDegreeOfParallelism = executionSettings.MaxDegreeOfParallelism
                },
                    body:               i => redisFunction(redisDb)
                    );

                var totalElapsedMilliseconds   = totalStopWatch.ElapsedMilliseconds;
                var documentsPerSecond         = executionSettings.NumberOfRepititions / (totalElapsedMilliseconds / 1000.0);
                var averageLatencyMilliseconds = (double)totalElapsedMilliseconds / executionSettings.NumberOfRepititions;

                return(string.Format(
                           "Processed: {0} items in {1}ms\r\nRate: {2}/sec\r\nLatency: {3}ms avg. per request",
                           executionSettings.NumberOfRepititions,
                           totalElapsedMilliseconds,
                           documentsPerSecond.ToString("0.00"),
                           averageLatencyMilliseconds
                           ));
            }
            catch (Exception exception)
            {
                return(exception.ToString());
            }
        }