码迷,mamicode.com
首页 > 其他好文 > 详细

redis使用

时间:2018-06-03 21:39:52      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:使用   evel   caching   collect   serve   IV   erb   key   AC   

安装为windows服务
redis-server.exe --service-install redis.conf --loglevel verbose
登录
redis-cli -h 127.0.0.1 -p 6379 -a 123

 Asp.net core应用 Redis,

Nuget :Microsoft.Extensions.Caching.Redis

 public void ConfigureServices(IServiceCollection services)
        {
           
           
            services.AddDistributedRedisCache(options =>
            {
                options.Configuration = "127.0.0.1,password=123456";
                options.InstanceName = "sample";

            });
        }
 [Route("api/[controller]")]
    public class ValuesController : Controller
    {
        private IDistributedCache _memoryCache;

        public ValuesController(IDistributedCache memoryCache)
        {
            _memoryCache = memoryCache;
        }

        // GET api/values
        [HttpGet]
        public string Get()
        {
            string key = System.Guid.NewGuid().ToString("N");
            string value = System.Guid.NewGuid().ToString("N");
            _memoryCache.SetString(key, value);
            return key;
        }

        // GET api/values/5
        [HttpGet("{key}")]
        public string Get(string key)
        {
            return _memoryCache.GetString(key);
        }

    }

 

redis使用

标签:使用   evel   caching   collect   serve   IV   erb   key   AC   

原文地址:https://www.cnblogs.com/gaocong/p/9130076.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!