增加Redis缓冲测试

This commit is contained in:
falcon 2022-04-22 10:08:01 +08:00
parent 4b93c9f129
commit 25dfda236a

View File

@ -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<ISugarCache>();
var sca = sp.GetService<ISugarCacheAsync>();
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<ISugarCache>();
var sca = sp.GetService<ISugarCacheAsync>();
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; }