参考文章地址: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. Vue相关开源项目库汇总 http://www.opendigg.com/tags/front-vue

    awesome-github-vue 是由OpenDigg整理并维护的Vue相关开源项目库集合.我们会定期同步OpenDigg上的项目到这里,也欢迎各位提交项目给我们. 如果收录的项目有错误,可以通过 ...

  2. [模板] BSGS

    BSGS是一种解决一类专门的问题的解法,主要是解决已知A, B, C,求X使得A^x = B (mod p)这一类问题. 解法很简单,先设x = i*m-j(m=ceil(sqrt(p))),然后进行 ...

  3. hdu 1512 Monkey King —— 左偏树

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1512 很简单的左偏树: 但突然对 rt 的关系感到混乱,改了半天才弄对: 注意是多组数据! #includ ...

  4. poj1201 Intervals——差分约束

    题目:http://poj.org/problem?id=1201 差分约束裸题: 设 s[i] 表示到 i 选了数的个数前缀和: 根据题意,可以建立以下三个限制关系: s[bi] >= s[a ...

  5. 单纯形&&线性规划

    沦为了背板子...wyfcyx的ppt #include<bits/stdc++.h> using namespace std; ; , inf = 1e18; int n, m, l, ...

  6. ubuntu 16.04 Hbase 安装

    1.解压安装包至路径 /usr/local 1.1.sudo tar -zxf ~/下载/hbase-1.1.2-bin.tar.gz -C /usr/local 2.将解压的文件名hbase-1.1 ...

  7. 2-1 创建第一个Vue实例

    https://cn.vuejs.org/ 生产版本是经过压缩后的版本,它里面把一些没用的警告的代码删除掉了所以它会更精悍一些. 直接引入CDN的网址我们就可以使用Vuejs了.使用生产版本或者CDN ...

  8. Sort List 典型链表

    https://leetcode.com/problems/sort-list/ Sort a linked list in O(n log n) time using constant space ...

  9. Network(Tarjan+LCA)

    http://poj.org/problem?id=3417 元宵节+情人节晚上刷的题,纪念一下.. 题意:给出n个点,m条边,然后Q个询问,每次询问输入一条边,输出加入此边后桥的个数.. #incl ...

  10. 【BZOJ1124】[POI2008]枪战Maf(基环树_构造)

    被教练勒令做题不能看题解后的第一道新题,自行 yy 了好久终于 AC 了(菜啊)--写博客纪念. 题目: BZOJ1124 分析: 考虑每个人向他要打的人连边.根据题意,所有点都有且只有一条出边.那么 ...