Пример #1
0
 StringGet(
     RedisServiceSettingsViewModel serviceSettings,
     StringGetViewModel stringGetParameters,
     ExecutionSettingsViewModel executionSettings)
 {
     return(ExecuteRedisFunction(
                serviceSettings:    serviceSettings,
                redisFunction:      redisDb => redisDb.StringGet(
                    stringGetParameters.Key
                    ),
                executionSettings:  executionSettings
                ));
 }
Пример #2
0
        GetRedisDb(
            RedisServiceSettingsViewModel serviceSettings)
        {
            var configurationString = string.Format(
                "{0}.redis.cache.windows.net,password={1}",
                serviceSettings.ServiceName,
                serviceSettings.ServiceKey
                );

            return(ConnectionMultiplexer
                   .Connect(configurationString)
                   .GetDatabase());
        }
Пример #3
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());
            }
        }