Created
September 17, 2015 16:30
-
-
Save tarasn/6b360f66742090a2596f to your computer and use it in GitHub Desktop.
A simple example to check Redis performance and index creation
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.Diagnostics; | |
| using System.Linq; | |
| using StackExchange.Redis; | |
| namespace ConsoleApplicationRedis | |
| { | |
| internal class Program | |
| { | |
| private static void Main(string[] args) | |
| { | |
| var redis = ConnectionMultiplexer.Connect("localhost"); | |
| var db = redis.GetDatabase(); | |
| var random = new Random((int) DateTime.Now.Ticks); | |
| var time = Time(() => | |
| { | |
| CreateUsers(db, random); | |
| }); | |
| Console.WriteLine(time.TotalSeconds + " TotalSeconds"); | |
| time = Time(() => | |
| { | |
| var gett = db.HashGet("users:123","name"); | |
| Console.WriteLine(gett); | |
| }); | |
| Console.WriteLine(time.TotalMilliseconds + " TotalMilliseconds"); | |
| time = Time(() => | |
| { | |
| var gett = db.SetMembers("name:name_1678"); | |
| foreach (var v in gett) | |
| { | |
| Console.WriteLine(v); | |
| } | |
| }); | |
| Console.WriteLine(time.TotalMilliseconds + " TotalMilliseconds"); | |
| Console.ReadLine(); | |
| } | |
| private static void CreateUsers(IDatabase db, Random random) | |
| { | |
| for (var i = 0; i < 1000; i++) | |
| { | |
| db.HashSet("users:" + i, new[] | |
| { | |
| new HashEntry("name", "name_" + i), | |
| new HashEntry("age", random.Next(1, 99)) | |
| }); | |
| db.SetAdd("name:name_" + i, i); | |
| } | |
| db.SetAdd("name:name_1678" ,234); | |
| } | |
| public static TimeSpan Time(Action action) | |
| { | |
| var stopwatch = Stopwatch.StartNew(); | |
| action(); | |
| stopwatch.Stop(); | |
| return stopwatch.Elapsed; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment