QuickRedis is a library that help you implement Redis quickly with useful methods.
Install QuickRedis
from Nuget
dotnet add package QuickRedis
nuget install QuickRedis
builder.Services.AddQuickRedis(options => {
options.Configuration = "localhost";
options.InstanceName = "main_";
});
private readonly IQuickRedisService _quickRedisService;
public TestController(IQuickRedisService quickRedisService)
{
_quickRedisService = quickRedisService;
}
# w/ gui
docker run -d --name redis_stack --restart unless-stopped -p 6379:6379 -p 8001:8001 -v redis_data:/data redis/redis-stack:latest
# w/o gui
docker run -d --name redis_stack_server --restart unless-stopped -p 6379:6379 -v redis_data:/data redis/redis-stack-server:latest
// GetAsync
var product = await _quickRedisService.GetAsync<Product>("unique_product_id");
var product = _quickRedisService.GetAsync<Product>("unique_product_id").Result;
// SetAsync
await _quickRedisService.SetAsync("unique_product_id", product);
_quickRedisService.SetAsync("unique_product_id", product).Wait();
// RemoveAsync
await _quickRedisService.RemoveAsync("unique_product_id");
_quickRedisService.RemoveAsync("unique_product_id").Wait();
// AddOrGetFuncAsync
List<string> TestMethod();
var methodResult = await _quickRedisService.AddOrGetFuncAsync<List<string>>("result_unique_key", () => TestMethod());
var methodResult = _quickRedisService.AddOrGetFuncAsync<List<string>>("result_unique_key", () => TestMethod()).Result;