参考文章地址:https://dotnetcoretutorials.com/2017/01/06/using-redis-cache-net-core/

具体步骤:

1   Install-Package Microsoft.Extensions.Caching.Redis

2‘

 public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(); services.AddDistributedRedisCache(option =>
{
option.Configuration = "127.0.0.1";
option.InstanceName = "master";
});
}

3:

[Route("api/[controller]")]
public class HomeController : Controller
{
private readonly IDistributedCache _distributedCache; public HomeController(IDistributedCache distributedCache)
{
_distributedCache = distributedCache;
} [HttpGet]
public async Task<string> Get()
{
var cacheKey = "TheTime";
var existingTime = _distributedCache.GetString(cacheKey);
if (!string.IsNullOrEmpty(existingTime))
{
return "Fetched from cache : " + existingTime;
}
else
{
existingTime = DateTime.UtcNow.ToString();
_distributedCache.SetString(cacheKey, existingTime);
return "Added to cache : " + existingTime;
}
}
}

  

net core 配置Redis Cache的更多相关文章

  1. ASP.NET Core 使用 Redis 客户端

    Mac OS 安装 Redis(用于连 Redis 服务器,方便查看数据):https://redis.io/topics/quickstart wget http://download.redis. ...

  2. Azure Redis Cache (4) 配置和管理Redis Cache

    <Windows Azure Platform 系列文章目录> 我们在创建完Azure Redis Cache后,经常需要切换Redis Cache的服务级别,这里我简单介绍一下使用Azu ...

  3. Windows Azure 系列-- Azure Redis Cache的配置和使用

    假设还没有配置Azure Power shell 能够參照这里进行配置:http://blog.csdn.net/lan_liang/article/details/46850221 打开Azure ...

  4. Azure Redis Cache (3) 创建和使用P级别的Redis Cache

    <Windows Azure Platform 系列文章目录> 在笔者之前的文档里面已经说明了,Azure Redis Cache分为三个不同的级别: - 基本,Basic,不包含SLA ...

  5. 利用Redis cache优化app查询速度实践

    注意:本篇文章译自speeding up existing app with a redis cache,如需要转载请注明出处. 发现问题 在应用解决方法之前,我们需要对我们面对的问题有一个清晰的认识 ...

  6. spring配置redis注解缓存

    前几天在spring整合Redis的时候使用了手动的方式,也就是可以手动的向redis添加缓存与清除缓存,参考:http://www.cnblogs.com/qlqwjy/p/8562703.html ...

  7. CentOS下配置redis允许远程连接

    1. 目的 因为想要学习redis,因此在虚拟机中安装了redis,为了实现在物理机可以访问redis,弄了好久:因此记录下来,以免忘记. 2. 环境 虚拟机:CentOS Linux release ...

  8. spring boot 配置redis

    先配置属性: # database name spring.redis.database=0 # server host spring.redis.host=127.0.0.1 # server pa ...

  9. ASP.NET Core 使用 Redis 实现分布式缓存:Docker、IDistributedCache、StackExchangeRedis

    ASP.NET Core 使用 Redis 实现分布式缓存:Docker.IDistributedCache.StackExchangeRedis 前提:一台 Linux 服务器.已安装 Docker ...

随机推荐

  1. linux 网络编程-基础篇01

    #Socket简介 是一个编程接口是一种特殊的文件描述符(everything in Unix is a file)并不仅限于TCPIP协议面向连接(Transmission Control Prot ...

  2. YTU 2705:用重载求距离

    2705: 用重载求距离. 时间限制: 1 Sec  内存限制: 128 MB 提交: 208  解决: 114 题目描述 使用函数重载的方法定义两个重名函数,分别求出整型数的两点间距离和浮点型数的两 ...

  3. 解决无线网卡 RTL8723BE ubuntu环境下不稳定情况

    jiqing@ThinkPad:~$ lspci | grep -i net 00:19.0 Ethernet controller: Intel Corporation Ethernet Conne ...

  4. IDEA Spark Streaming 操作(套接字流)

    import org.apache.spark.SparkConf import org.apache.spark.streaming.{Seconds, StreamingContext} obje ...

  5. html5拨打电话及发短信

    1.最常用WEB页面一键拨号的电话拨打功能 <a href="tel:15088888888">拨号</a> 2.最常用WEB页面一键发送短信功能: < ...

  6. Coursera Algorithms week4 基础标签表 练习测验:Inorder traversal with constant extra space

    题目原文: Design an algorithm to perform an inorder traversal of a binary search tree using only a const ...

  7. web安全:防止浏览器记住或自动填写用户名和密码(表单)的终极解决方案

    最近项目上要求做到这一点,在网上搜了一圈,发现都是不完美的,不兼容全部的浏览器,于是只能自己摸索了,最终得出了终极解决方案: 涉及: disabled 或 readonly display:none; ...

  8. Django 内容回顾

    模板 变量 {{ }} 标签 {% %} if elif else for empty forloop() with...as csrf_token 过滤器 default length add da ...

  9. ACM_梦中的函数

    梦中的函数 Time Limit: 2000/1000ms (Java/Others) Problem Description: 寒假那段时间,每天刷题的小G连做梦都是代码,于是有了这道题. 给定一个 ...

  10. linux的touch命令

    linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 1.命令格式: touch [选项]... 文件... 2.命令参数: -a    ...