public IActionResult Details(string id) { Product product; var obj = cache.StringGet(id); if (obj.HasValue == true) { product = JsonConvert.DeserializeObject <Product>(obj); } else { product = _repositoryManagement.Get <Product>(id); product.counter = product.counter + 1; _repositoryManagement.UpdateInfo <Product>(id, product); } return(Ok(product)); }
/// <summary> /// Obtenir du cache partagé /// </summary> /// <param name="DirectInvoiceid"></param> /// <returns></returns> public DirectInvoice GetDirectInvoice(string iddirectinvoice) { DirectInvoice retour = null; try { // Obtien d'abord l'objet sur MemCached si Existe if (env != null) { StackExchange.Redis.ConfigurationOptions redisconfig = new StackExchange.Redis.ConfigurationOptions(); redisconfig.EndPoints.Add("22ec9a54-2921-43af-a4e9-9b1e7aff2b9b.pdb.ovh.net", 21784); redisconfig.Password = "******"; StackExchange.Redis.ConnectionMultiplexer redis = StackExchange.Redis.ConnectionMultiplexer.Connect(redisconfig); StackExchange.Redis.IDatabase redisDb = redis.GetDatabase(); StackExchange.Redis.RedisKey key = iddirectinvoice; StackExchange.Redis.RedisValue val = redisDb.StringGet(key, StackExchange.Redis.CommandFlags.None); if (!string.IsNullOrWhiteSpace(val)) { retour = new DirectInvoice(); retour.FromStringData(val); } } // sinon regarde en base if (retour == null) { Dictionary <string, object> ins = new Dictionary <string, object>(); ins.Add("iddirectinvoice", iddirectinvoice); retour = this.GetOneDefault <DirectInvoice>(ins); } return(retour); } catch (Exception ex) { throw new Exception("GetDirectInvoice " + ex.Message, ex); } }
static void Main(string[] args) { RedisHelper.Initialization(new CSRedis.CSRedisClient("127.0.0.1:6379,database=1,asyncPipeline=true,preheat=100,poolsize=100")); cli.Set("TestMGet_null1", ""); RedisHelper.Set("TestMGet_null1", ""); sedb.StringSet("TestMGet_string1", String); ThreadPool.SetMinThreads(10001, 10001); Stopwatch sw = new Stopwatch(); var tasks = new List <Task>(); cli.FlushAll(); sw.Reset(); sw.Start(); for (var a = 0; a < 100000; a++) { var tmp = Guid.NewGuid().ToString(); sedb.StringSet(tmp, String); var val = sedb.StringGet(tmp); if (val != String) { throw new Exception("not equal"); } } sw.Stop(); Console.WriteLine("StackExchange(0-100000): " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); tasks = new List <Task>(); for (var a = 0; a < 100000; a++) { tasks.Add(Task.Run(() => { var tmp = Guid.NewGuid().ToString(); sedb.StringSet(tmp, String); var val = sedb.StringGet(tmp); if (val != String) { throw new Exception("not equal"); } })); } Task.WaitAll(tasks.ToArray()); sw.Stop(); Console.WriteLine("StackExchange(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms"); tasks.Clear(); sw.Reset(); sw.Start(); Task.Run(async() => { for (var a = 0; a < 100000; a++) { var tmp = Guid.NewGuid().ToString(); await sedb.StringSetAsync(tmp, String); var val = await sedb.StringGetAsync(tmp); if (val != String) { throw new Exception("not equal"); } } }).Wait(); sw.Stop(); Console.WriteLine("StackExchangeAsync(0-100000): " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); tasks = new List <Task>(); for (var a = 0; a < 100000; a++) { tasks.Add(Task.Run(async() => { var tmp = Guid.NewGuid().ToString(); await sedb.StringSetAsync(tmp, String); var val = await sedb.StringGetAsync(tmp); if (val != String) { throw new Exception("not equal"); } })); } Task.WaitAll(tasks.ToArray()); sw.Stop(); Console.WriteLine("StackExchangeAsync(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms\r\n"); tasks.Clear(); sw.Reset(); sw.Start(); for (var a = 0; a < 100000; a++) { var tmp = Guid.NewGuid().ToString(); cli.Set(tmp, String); var val = cli.Get(tmp); if (val != String) { throw new Exception("not equal"); } } sw.Stop(); Console.WriteLine("FreeRedis(0-100000): " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); tasks = new List <Task>(); for (var a = 0; a < 100000; a++) { tasks.Add(Task.Run(() => { var tmp = Guid.NewGuid().ToString(); cli.Set(tmp, String); var val = cli.Get(tmp); if (val != String) { throw new Exception("not equal"); } })); } Task.WaitAll(tasks.ToArray()); sw.Stop(); Console.WriteLine("FreeRedis(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms"); tasks.Clear(); sw.Reset(); sw.Start(); Task.Run(async() => { for (var a = 0; a < 100000; a++) { var tmp = Guid.NewGuid().ToString(); await cli.SetAsync(tmp, String); var val = await cli.GetAsync(tmp); if (val != String) { throw new Exception("not equal"); } } }).Wait(); sw.Stop(); Console.WriteLine("FreeRedisAsync(0-100000): " + sw.ElapsedMilliseconds + "ms"); //FreeRedis.Internal.AsyncRedisSocket.sb.Clear(); //FreeRedis.Internal.AsyncRedisSocket.sw.Start(); sw.Reset(); sw.Start(); tasks = new List <Task>(); for (var a = 0; a < 100000; a++) { tasks.Add(Task.Run(async() => { var tmp = Guid.NewGuid().ToString(); await cli.SetAsync(tmp, String); var val = await cli.GetAsync(tmp); if (val != String) { throw new Exception("not equal"); } })); } Task.WaitAll(tasks.ToArray()); sw.Stop(); //var sbstr = FreeRedis.Internal.AsyncRedisSocket.sb.ToString() //sbstr = sbstr + sbstr.Split("\r\n").Length + "条消息 ; Console.WriteLine("FreeRedisAsync(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms"); tasks.Clear(); sw.Reset(); sw.Start(); using (var pipe = cli.StartPipe()) { for (var a = 0; a < 100000; a++) { var tmp = Guid.NewGuid().ToString(); pipe.Set(tmp, String); var val = pipe.Get(tmp); } var vals = pipe.EndPipe(); for (var a = 1; a < 100000; a += 2) { if (vals[a].ToString() != String) { throw new Exception("not equal"); } } } sw.Stop(); Console.WriteLine("FreeRedisPipeline(0-100000): " + sw.ElapsedMilliseconds + "ms\r\n"); //sw.Reset(); //sw.Start(); //for (var a = 0; a < 100000; a++) // cli.Call(new CommandPacket("SET").Input("TestMGet_string1").InputRaw(String)); //sw.Stop(); //Console.WriteLine("FreeRedis2: " + sw.ElapsedMilliseconds + "ms"); //sw.Reset(); //sw.Start(); //for (var a = 0; a < 100000; a++) //{ // using (var rds = cli.GetTestRedisSocket()) // { // var cmd = new CommandPacket("SET").Input("TestMGet_string1").InputRaw(String); // rds.Write(cmd); // cmd.Read<string>(); // } //} //sw.Stop(); //Console.WriteLine("FreeRedis4: " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); for (var a = 0; a < 100000; a++) { var tmp = Guid.NewGuid().ToString(); RedisHelper.Set(tmp, String); var val = RedisHelper.Get(tmp); if (val != String) { throw new Exception("not equal"); } } sw.Stop(); Console.WriteLine("CSRedisCore(0-100000): " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); tasks = new List <Task>(); for (var a = 0; a < 100000; a++) { tasks.Add(Task.Run(() => { var tmp = Guid.NewGuid().ToString(); RedisHelper.Set(tmp, String); var val = RedisHelper.Get(tmp); if (val != String) { throw new Exception("not equal"); } })); } Task.WaitAll(tasks.ToArray()); sw.Stop(); Console.WriteLine("CSRedisCore(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms"); tasks.Clear(); sw.Reset(); sw.Start(); Task.Run(async() => { for (var a = 0; a < 100000; a++) { var tmp = Guid.NewGuid().ToString(); await RedisHelper.SetAsync(tmp, String); var val = await RedisHelper.GetAsync(tmp); if (val != String) { throw new Exception("not equal"); } } }).Wait(); sw.Stop(); Console.WriteLine("CSRedisCoreAsync(0-100000): " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); tasks = new List <Task>(); for (var a = 0; a < 100000; a++) { tasks.Add(Task.Run(async() => { var tmp = Guid.NewGuid().ToString(); await RedisHelper.SetAsync(tmp, String); var val = await RedisHelper.GetAsync(tmp); //if (val != String) throw new Exception("not equal"); })); } Task.WaitAll(tasks.ToArray()); sw.Stop(); Console.WriteLine("CSRedisCoreAsync(Task.WaitAll 100000): " + sw.ElapsedMilliseconds + "ms\r\n"); tasks.Clear(); }
static void Main(string[] args) { RedisHelper.Initialization(new CSRedis.CSRedisClient("127.0.0.1:6379,database=1,asyncPipeline=true,preheat=100,poolsize=100")); cli.Set("TestMGet_null1", ""); RedisHelper.Set("TestMGet_null1", ""); sedb.StringSet("TestMGet_string1", String); ThreadPool.SetMinThreads(1000, 1000); Stopwatch sw = new Stopwatch(); cli.FlushAll(); sw.Reset(); sw.Start(); for (var a = 0; a < 10000; a++) { var tmp = Guid.NewGuid().ToString(); sedb.StringSet(tmp, String); var val = sedb.StringGet(tmp); if (val != String) { throw new Exception("not equal"); } } sw.Stop(); Console.WriteLine("StackExchange(0-10000): " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); var tasks = new List <Task>(); for (var a = 0; a < 10000; a++) { tasks.Add(Task.Run(() => { var tmp = Guid.NewGuid().ToString(); sedb.StringSet(tmp, String); var val = sedb.StringGet(tmp); if (val != String) { throw new Exception("not equal"); } })); } Task.WaitAll(tasks.ToArray()); sw.Stop(); Console.WriteLine("StackExchange(Task.WaitAll 10000): " + sw.ElapsedMilliseconds + "ms"); tasks.Clear(); sw.Reset(); sw.Start(); Task.Run(async() => { for (var a = 0; a < 10000; a++) { var tmp = Guid.NewGuid().ToString(); await sedb.StringSetAsync(tmp, String); var val = await sedb.StringGetAsync(tmp); if (val != String) { throw new Exception("not equal"); } } }).Wait(); sw.Stop(); Console.WriteLine("StackExchangeAsync(0-10000): " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); tasks = new List <Task>(); for (var a = 0; a < 10000; a++) { tasks.Add(Task.Run(async() => { var tmp = Guid.NewGuid().ToString(); await sedb.StringSetAsync(tmp, String); var val = await sedb.StringGetAsync(tmp); if (val != String) { throw new Exception("not equal"); } })); } Task.WaitAll(tasks.ToArray()); sw.Stop(); Console.WriteLine("StackExchangeAsync(Task.WaitAll 10000): " + sw.ElapsedMilliseconds + "ms\r\n"); tasks.Clear(); //sw.Reset(); //sw.Start(); //using (var local = cli.GetShareClient()) //{ // local.ClientReply(ClientReplyType.off); // for (var a = 0; a < 10000; a++) // local.Set("TestMGet_string1", String); // local.ClientReply(ClientReplyType.on); //} //sw.Stop(); //Console.WriteLine("hiredis0: " + sw.ElapsedMilliseconds + "ms"); //var sw2 = new Stopwatch(); //sw.Reset(); //sw.Start(); //using (var rds = cli.GetTestRedisSocket()) //{ // var strea = rds.Stream; // for (var a = 0; a < 10000; a++) // { // rds.Write(new CommandPacket("SET").Input("TestMGet_string1").InputRaw(String)); // } // sw2.Reset(); // sw2.Start(); // for (var a = 0; a < 10000; a++) // { // strea.ReadByte(); // var sb = new StringBuilder(); // char c; // bool should_break = false; // while (true) // { // c = (char)strea.ReadByte(); // if (c == '\r') // TODO: remove hardcoded // should_break = true; // else if (c == '\n' && should_break) // break; // else // { // sb.Append(c); // should_break = false; // } // } // } // sw2.Stop(); //} //sw.Stop(); //Console.WriteLine("hiredis1: " + sw.ElapsedMilliseconds + "ms, " + sw2.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); for (var a = 0; a < 10000; a++) { var tmp = Guid.NewGuid().ToString(); cli.Set(tmp, String); var val = cli.Get(tmp); if (val != String) { throw new Exception("not equal"); } } sw.Stop(); Console.WriteLine("hiredis(0-10000): " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); tasks = new List <Task>(); for (var a = 0; a < 10000; a++) { tasks.Add(Task.Run(() => { var tmp = Guid.NewGuid().ToString(); cli.Set(tmp, String); var val = cli.Get(tmp); if (val != String) { throw new Exception("not equal"); } })); } Task.WaitAll(tasks.ToArray()); sw.Stop(); Console.WriteLine("hiredis(Task.WaitAll 10000): " + sw.ElapsedMilliseconds + "ms"); tasks.Clear(); //sw.Reset(); //sw.Start(); //Task.Run(async () => //{ // for (var a = 0; a < 10000; a++) // { // var tmp = Guid.NewGuid().ToString(); // await cli.SetAsync(tmp, String); // var val = await cli.GetAsync(tmp); // if (val != String) throw new Exception("not equal"); // } //}).Wait(); //sw.Stop(); //Console.WriteLine("hiredisAsync(0-10000): " + sw.ElapsedMilliseconds + "ms"); //sw.Reset(); //sw.Start(); //tasks = new List<Task>(); //for (var a = 0; a < 10000; a++) //{ // tasks.Add(Task.Run(async () => // { // var tmp = Guid.NewGuid().ToString(); // await cli.SetAsync(tmp, String); // var val = await cli.GetAsync(tmp); // if (val != String) throw new Exception("not equal"); // })); //} //Task.WaitAll(tasks.ToArray()); //sw.Stop(); //Console.WriteLine("hiredisAsync(Task.WaitAll 10000): " + sw.ElapsedMilliseconds + "ms"); //tasks.Clear(); sw.Reset(); sw.Start(); using (var pipe = cli.StartPipe()) { for (var a = 0; a < 10000; a++) { var tmp = Guid.NewGuid().ToString(); pipe.Set(tmp, String); var val = pipe.Get(tmp); } var vals = pipe.EndPipe(); for (var a = 1; a < 10000; a += 2) { if (vals[a].ToString() != String) { throw new Exception("not equal"); } } } sw.Stop(); Console.WriteLine("hiredisPipeline(0-10000): " + sw.ElapsedMilliseconds + "ms\r\n"); //sw.Reset(); //sw.Start(); //for (var a = 0; a < 10000; a++) // cli.Call(new CommandPacket("SET").Input("TestMGet_string1").InputRaw(String)); //sw.Stop(); //Console.WriteLine("hiredis2: " + sw.ElapsedMilliseconds + "ms"); //sw.Reset(); //sw.Start(); //for (var a = 0; a < 10000; a++) //{ // using (var rds = cli.GetTestRedisSocket()) // { // var cmd = new CommandPacket("SET").Input("TestMGet_string1").InputRaw(String); // rds.Write(cmd); // cmd.Read<string>(); // } //} //sw.Stop(); //Console.WriteLine("hiredis4: " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); for (var a = 0; a < 10000; a++) { var tmp = Guid.NewGuid().ToString(); RedisHelper.Set(tmp, String); var val = RedisHelper.Get(tmp); if (val != String) { throw new Exception("not equal"); } } sw.Stop(); Console.WriteLine("CSRedisCore(0-10000): " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); tasks = new List <Task>(); for (var a = 0; a < 10000; a++) { tasks.Add(Task.Run(() => { var tmp = Guid.NewGuid().ToString(); RedisHelper.Set(tmp, String); var val = RedisHelper.Get(tmp); if (val != String) { throw new Exception("not equal"); } })); } Task.WaitAll(tasks.ToArray()); sw.Stop(); Console.WriteLine("CSRedisCore(Task.WaitAll 10000): " + sw.ElapsedMilliseconds + "ms"); tasks.Clear(); sw.Reset(); sw.Start(); Task.Run(async() => { for (var a = 0; a < 10000; a++) { var tmp = Guid.NewGuid().ToString(); await RedisHelper.SetAsync(tmp, String); var val = await RedisHelper.GetAsync(tmp); if (val != String) { throw new Exception("not equal"); } } }).Wait(); sw.Stop(); Console.WriteLine("CSRedisCoreAsync(0-10000): " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); tasks = new List <Task>(); for (var a = 0; a < 10000; a++) { tasks.Add(Task.Run(async() => { var tmp = Guid.NewGuid().ToString(); await RedisHelper.SetAsync(tmp, String); var val = await RedisHelper.GetAsync(tmp); //if (val != String) throw new Exception("not equal"); })); } Task.WaitAll(tasks.ToArray()); sw.Stop(); Console.WriteLine("CSRedisCoreAsync(Task.WaitAll 10000): " + sw.ElapsedMilliseconds + "ms\r\n"); tasks.Clear(); }