redis使用

安装为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);
        }

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