当前位置: 首页 > news >正文

太原建站服务腾讯公司网页设计

太原建站服务,腾讯公司网页设计,滕州网站制作哪家好,他达拉非片说明书1、安装redis Redis在windows平台上不受官方支持#xff0c;所以想要在window安装Redis就必须去下载windows提供的安装包。安装地址#xff1a;https://github.com/tporadowski/redis/releases 2、在NueGet安装包 3、在appsettings.json文件里面添加Redis相关配置信息 所以想要在window安装Redis就必须去下载windows提供的安装包。安装地址https://github.com/tporadowski/redis/releases 2、在NueGet安装包 3、在appsettings.json文件里面添加Redis相关配置信息 Redis: {Connection: 127.0.0.1:6379,passwordfoobared, //连接地址端口号密码InstanceName: local, //实例名称DefaultDB: 8 //db8数据库} redis的密码可在安装目录下找到redis.windows.conf文件打开查看 4、创建RedisHelper类代码如下 using StackExchange.Redis; using System.Collections.Concurrent;namespace WebApi.Redis {public class RedisHelper : IDisposable{//连接字符串private string _connectionString;//实例名称private string _instanceName;//默认数据库private int _defaultDB;private ConcurrentDictionarystring, ConnectionMultiplexer _connections;public RedisHelper(string connectionString, string instanceName, int defaultDB 0){_connectionString connectionString;_instanceName instanceName;_defaultDB defaultDB;_connections new ConcurrentDictionarystring, ConnectionMultiplexer();}/// summary/// 获取ConnectionMultiplexer/// /summary/// returns/returnsprivate ConnectionMultiplexer GetConnect(){return _connections.GetOrAdd(_instanceName, p ConnectionMultiplexer.Connect(_connectionString));}/// summary/// 获取数据库/// /summary/// param nameconfigName/param/// param namedb默认为0优先代码的db配置其次config中的配置/param/// returns/returnspublic IDatabase GetDatabase(){return GetConnect().GetDatabase(_defaultDB);}public IServer GetServer(string configName null, int endPointsIndex 0){var confOption ConfigurationOptions.Parse(_connectionString);return GetConnect().GetServer(confOption.EndPoints[endPointsIndex]);}public ISubscriber GetSubscriber(string configName null){return GetConnect().GetSubscriber();}public void Dispose(){if (_connections ! null _connections.Count 0){foreach (var item in _connections.Values){item.Close();}}}} } 5、在program.cs中添加依赖 //redis缓存 var section builder.Configuration.GetSection(Redis); //连接字符串 string _connectionString section.GetSection(Connection).Value; //实例名称 string _instanceName section.GetSection(InstanceName).Value; //默认数据库 int _defaultDB int.Parse(section.GetSection(DefaultDB).Value ?? 0); builder.Services.AddSingleton(new RedisHelper(_connectionString, _instanceName, _defaultDB)); 6、控制器中可用直接注入依赖使用 using Microsoft.AspNetCore.Mvc; using StackExchange.Redis; using WebApi.Redis;namespace WebApi.Controllers {[Route(api/[controller]/[action])][ApiController]public class TestController : ControllerBase{private readonly IDatabase _redis;public TestController(RedisHelper redis) {_redis redis.GetDatabase();}[HttpGet]public Person GetPerson(){string? name _redis.StringGet(name);return new Person(name, 18);}[HttpPost]public string SavePerson(string name){_redis.StringSet(name,name);return 保存成功 name;}} } 7.运行测试运行时候确保redis服务打开
http://www.pierceye.com/news/39695/

相关文章:

  • 地方旅游网站怎么做德阳互联免费云主机
  • 购物网站英文介绍互联网创业项目概述
  • 低价建设网站图书馆网站建设情况说明
  • 有了域名与服务器怎么建网站每一天做网站
  • 建网站得多少钱wordpress做淘宝客
  • 网站技术的解决方案html旅游网页制作代码
  • ink域名网站群晖ds218 做网站
  • 购物网站开发流程图考试微网站开发
  • 网站 需求文档公司名字测吉凶免费
  • google网站提交php网站留言板模板下载
  • 石家庄php网站建设做外贸一般做什么
  • 汉南网站建设建设工程扣分查询网站
  • 个人电影网站建设网站建设的整体流程有哪些?
  • 福建宏盛建设集团网站学ps网课平台哪个好
  • 关于网站建设的请示报告吕梁市住房与城乡建设厅网站
  • win2012 iis添加网站南宁市网页设计
  • 源码下载网站源码外贸set是什么意思
  • 徐州网站制作怎么做小程序商家
  • 我想自己做网站江西省上饶市城乡建设网站
  • 园林网站源代码网站备案流程慢
  • 免费背景图片素材网站免费素材图片下载
  • 网站开发精品课程常见网页制作软件
  • 深圳松岗做网站的老板让做公司网站设计
  • 电子商务网站建设的总体设计网站服务内容填网站建设可以
  • 如果只做p2p种子搜索网站网站建设 职责
  • 成都住房和城乡建设局 网站首页可以做甩货的电商网站
  • 提升网站安全热搜榜排名前十
  • 桃源县建设局网站学校校园网站 资源建设方案
  • 网络传销是否传销网站优化过度的表现
  • 网站建设中最重要的网站找回备案密码怎么不对