From 25dfda236ad6119f58e101c8114c02188f41c349 Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Fri, 22 Apr 2022 10:08:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Redis=E7=BC=93=E5=86=B2?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Falcon.SugarApi.Test/CacheTest.cs | 37 ++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/Falcon.SugarApi.Test/CacheTest.cs b/Falcon.SugarApi.Test/CacheTest.cs index b3c7561..ab7d723 100644 --- a/Falcon.SugarApi.Test/CacheTest.cs +++ b/Falcon.SugarApi.Test/CacheTest.cs @@ -1,11 +1,7 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Falcon.SugarApi.Cache; using Microsoft.Extensions.DependencyInjection; -using Falcon.SugarApi.Cache; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; using System.Diagnostics; namespace Falcon.SugarApi.Test @@ -15,18 +11,35 @@ namespace Falcon.SugarApi.Test { [TestMethod] public void MemoryTest() { - var sw = new Stopwatch(); var services = new ServiceCollection() as IServiceCollection; services.AddSugarMemoryCache(op => { }); - var ts = new TimeSpan(0, 1, 0); - var strResult = ""; - int runTimes = 10000; var sp = services.BuildServiceProvider().CreateScope().ServiceProvider; var sc = sp.GetService(); var sca = sp.GetService(); + RunCache(sc, sca); + } + [TestMethod] + public void RedisTest() { + var sw = new Stopwatch(); + var services = new ServiceCollection() as IServiceCollection; + services.AddSugarRedisCache(op => { + op.Configuration = "127.0.0.1:7001,password=123654"; + op.InstanceName = "CacheTest:RedisTest"; + }); + var sp = services.BuildServiceProvider().CreateScope().ServiceProvider; + var sc = sp.GetService(); + var sca = sp.GetService(); + RunCache(sc, sca); + } + + private static void RunCache(ISugarCache? sc, ISugarCacheAsync? sca) { + var sw = new Stopwatch(); + var ts = new TimeSpan(0, 1, 0); + var strResult = ""; + int runTimes = 10000; var key = Guid.NewGuid().ToString(); var strValue = Guid.NewGuid().ToString(); //字符串同步存储 @@ -101,10 +114,8 @@ namespace Falcon.SugarApi.Test sw.Stop(); Console.WriteLine($"GetValueAsync 一次执行时间{sw.ElapsedMilliseconds}毫秒"); Assert.IsTrue(obj.Equals(objResult)); - } - internal class CacheTestModel { public int Id { get; set; }