Created
November 14, 2014 11:27
-
-
Save nickheppleston/35a71bdd4682e01a0099 to your computer and use it in GitHub Desktop.
Redis Performance Test - Azure Redis vs. Local Install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using StackExchange.Redis; | |
namespace RedisPerfTest | |
{ | |
class Program | |
{ | |
const string AZURE_REDIS_CONNECTION_STRING = "[HOSTNAME].redis.cache.windows.net,ssl=false,password=[PASSWORD],allowAdmin=true"; | |
const string LOCAL_REDIS_CONNECTION_STRING = "localhost:6379,ssl=false,allowAdmin=true"; | |
static void Main(string[] args) | |
{ | |
//var cacheConnection = ConnectionMultiplexer.Connect(AZURE_REDIS_CONNECTION_STRING); | |
var cacheConnection = ConnectionMultiplexer.Connect(LOCAL_REDIS_CONNECTION_STRING); | |
Console.WriteLine("Starting Redis Perf Test"); | |
for (int c = 0; c < 3; c++) | |
{ | |
FlushCacheDb(cacheConnection); // Flush the cache databases before we start the test. | |
var cache = cacheConnection.GetDatabase(); | |
var stopwatch = Stopwatch.StartNew(); | |
// Set Cache Items | |
for (int i = 0; i < 1000; i++) | |
{ | |
var cacheKey = i.ToString(); | |
var cacheItem = i; | |
cache.StringSet(cacheKey, (int)cacheItem, TimeSpan.FromMinutes(90)); | |
} | |
// Retrieve Cache Items | |
for (int i = 0; i < 1000; i++) | |
{ | |
var cacheKey = i.ToString(); | |
var cacheItem = (int)cache.StringGet(cacheKey); | |
} | |
stopwatch.Stop(); | |
Console.WriteLine(String.Format("Iteration {0} - Elapsed Seconds/Milliseconds: {1} / {2}", c, stopwatch.Elapsed.TotalSeconds, stopwatch.ElapsedMilliseconds)); | |
} | |
Console.WriteLine("Finished Redis Perf Test"); | |
Console.ReadLine(); | |
} | |
static void FlushCacheDb(ConnectionMultiplexer cacheConnection) | |
{ | |
var endpoints = cacheConnection.GetEndPoints(true); | |
foreach (var endpoint in endpoints) | |
{ | |
var server = cacheConnection.GetServer(endpoint); | |
server.FlushAllDatabases(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment