Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/liuyl1992/chaunceeasyredis
:boom: EasyRedis's improved version.
https://github.com/liuyl1992/chaunceeasyredis
easy-redis redis stackexchange standard-library
Last synced: about 1 month ago
JSON representation
:boom: EasyRedis's improved version.
- Host: GitHub
- URL: https://github.com/liuyl1992/chaunceeasyredis
- Owner: liuyl1992
- Created: 2018-05-17T05:00:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-03T02:48:52.000Z (about 6 years ago)
- Last Synced: 2024-11-13T04:54:25.206Z (2 months ago)
- Topics: easy-redis, redis, stackexchange, standard-library
- Language: C#
- Homepage:
- Size: 33.2 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![](https://cdn-images-1.medium.com/max/1600/0*4xFP6mgp50R8bY7g.)
# :boom: ChaunceEasyRedisChaunceEasyRedis is a free, open source,RedisService built on the .NETStandard platform.
[![ http://www.cnblogs.com/xiaoliangge/](https://badges.gitter.im/Join%20Chat.svg)](http://www.cnblogs.com/xiaoliangge/)
## About ChaunceEasyRedis
#### Please visit our website at http://www.cnblogs.com/xiaoliangge/ for the most current information about this project.
ChaunceEasyRedis reference https://github.com/dotnetcore/EasyCaching
ChaunceEasyRedis is free,open source.## :boom: How to use
### Step 1 : ConfigureServices```csharp
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
//注入ChaunceRedisCache
services.AddChaunceRedisCache(option =>
{
option.Database = 0;
option.Endpoints.Add(new ServerEndPoint("localhost", 6379));
option.DefaultCustomKey = "chaunce:";
});
}
}
```
### Step 2 : Write code in you controller
```csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Chaunce.EasyRedis;
using Microsoft.AspNetCore.Mvc;namespace ExampleWeb.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
private readonly IRedisCache _provider;
public ValuesController(IRedisCache provider)
{
_provider = provider;
}
// GET api/values
[HttpGet]
public ActionResult> Get()
{
_provider.CustomPrefixKey = "www:";//改边默认key
_provider.Set("demo", "yyy", TimeSpan.FromMinutes(1));
var str2 = _provider.Get("demo", () => { return "缓存"; }, TimeSpan.FromMinutes(1));
_provider.CustomPrefixKey = "EEE:";//继续改边默认key
var str3 = _provider.Get("demo", () => { return "缓存"; }, TimeSpan.FromMinutes(1));return new string[] { "value1", "value2" };
}// GET api/values/5
[HttpGet("{id}")]
public ActionResult Get(int id)
{
return "value";
}// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}```