From f9c9d13c682511820364ff68a61ca6222b5ef88c Mon Sep 17 00:00:00 2001
From: zhangqi <2794379662@qq.com>
Date: Thu, 25 Feb 2021 15:13:26 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0redis=E6=94=AF=E6=8C=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
QRCodeService/QRCodeService.csproj | 2 ++
QRCodeService/Startup.cs | 3 +++
QRCodeService/appsettings.json | 7 +++++++
3 files changed, 12 insertions(+)
diff --git a/QRCodeService/QRCodeService.csproj b/QRCodeService/QRCodeService.csproj
index 3ef2f5f..83cb3b3 100644
--- a/QRCodeService/QRCodeService.csproj
+++ b/QRCodeService/QRCodeService.csproj
@@ -29,6 +29,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
@@ -37,6 +38,7 @@
+
diff --git a/QRCodeService/Startup.cs b/QRCodeService/Startup.cs
index 3e35c0c..ecc6f47 100644
--- a/QRCodeService/Startup.cs
+++ b/QRCodeService/Startup.cs
@@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Caching.Redis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@@ -74,6 +75,8 @@ namespace QRCodeService
//Queries
services.AddScoped();
services.AddScoped();
+ //redis cache
+ services.AddDistributedRedisCache(options=>options.Configuration=Configuration.GetSection("redis:default").Value);
}
diff --git a/QRCodeService/appsettings.json b/QRCodeService/appsettings.json
index 365ebe8..d2edee1 100644
--- a/QRCodeService/appsettings.json
+++ b/QRCodeService/appsettings.json
@@ -42,5 +42,12 @@
"Properties": {
"Application": "SerilogExample"
}
+ },
+ "Redis": {
+ "Default": {
+ "Connection": "127.0.0.1:6379",
+ "InstanceName": "local",
+ "DefaultDB": 8
+ }
}
}