Skip to content

hadieht/Redis-Cache-Net5

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Redis Cache Library in Net5 and sample Api with Cache

Redis Cache library with simple usage in .Net 5

What is this ?

Simple library to Using Redis Cache In .NET Core Projects You can use this Library in Microservice Architecture with Client-Server Pattern for Cache. also you can assign db0, db1, for each Microservice

How to use ?

First you must install redis server. in quickly way you can install chocolaty and install redis through it. then run following command in cmd (run as administrator);

C:\> redis-server 

Then :

1- add required services to Startup class as below :

      services.AddStackExchangeRedisExtensions(option =>
			{
				return Configuration.GetSection("Redis").Get<RedisConnectionConfiguration>();
			});

2- Use IRedisCacheService in your app :

  [ApiController]
	[Route("cache")]
	public class HomeController : ControllerBase
	{
		private readonly IRedisCacheClient redisCacheClient;

		public HomeController(IRedisCacheClient redisCacheClient)
		{
			this.redisCacheClient = redisCacheClient;
		}

		[Route("getset")]
		[HttpGet]
		public async Task<IActionResult> SimpleGetSet()
		{
			await redisCacheClient.GetDbFromConfiguration().AddAsync<string>("mynames", "hadi", DateTimeOffset.Now.AddMinutes(10));

			var value = await redisCacheClient.GetDbFromConfiguration().GetAsync<string>("mynames");

			return Ok(value);

		}
   }

About

Redis Cache library with simple usage in .Net 5

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages