增加Redis缓冲测试
This commit is contained in:
parent
4b93c9f129
commit
25dfda236a
|
@ -1,11 +1,7 @@
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Falcon.SugarApi.Cache;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Falcon.SugarApi.Cache;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Falcon.SugarApi.Test
|
namespace Falcon.SugarApi.Test
|
||||||
|
@ -15,18 +11,35 @@ namespace Falcon.SugarApi.Test
|
||||||
{
|
{
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void MemoryTest() {
|
public void MemoryTest() {
|
||||||
var sw = new Stopwatch();
|
|
||||||
var services = new ServiceCollection() as IServiceCollection;
|
var services = new ServiceCollection() as IServiceCollection;
|
||||||
services.AddSugarMemoryCache(op => {
|
services.AddSugarMemoryCache(op => {
|
||||||
|
|
||||||
});
|
});
|
||||||
var ts = new TimeSpan(0, 1, 0);
|
|
||||||
var strResult = "";
|
|
||||||
int runTimes = 10000;
|
|
||||||
var sp = services.BuildServiceProvider().CreateScope().ServiceProvider;
|
var sp = services.BuildServiceProvider().CreateScope().ServiceProvider;
|
||||||
var sc = sp.GetService<ISugarCache>();
|
var sc = sp.GetService<ISugarCache>();
|
||||||
var sca = sp.GetService<ISugarCacheAsync>();
|
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 key = Guid.NewGuid().ToString();
|
||||||
var strValue = Guid.NewGuid().ToString();
|
var strValue = Guid.NewGuid().ToString();
|
||||||
//字符串同步存储
|
//字符串同步存储
|
||||||
|
@ -101,10 +114,8 @@ namespace Falcon.SugarApi.Test
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
Console.WriteLine($"GetValueAsync 一次执行时间{sw.ElapsedMilliseconds}毫秒");
|
Console.WriteLine($"GetValueAsync 一次执行时间{sw.ElapsedMilliseconds}毫秒");
|
||||||
Assert.IsTrue(obj.Equals(objResult));
|
Assert.IsTrue(obj.Equals(objResult));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal class CacheTestModel
|
internal class CacheTestModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user