首页 > 其他 > 详细

redis使用

时间:2018-06-03 21:14:50      阅读:263      评论:0      收藏:0      [点我收藏+]
安装为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使用

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!