【发布时间】:2022-02-10 16:05:04
【问题描述】:
.net 6 和 Redis 缓存集成使用集合、散列。 请为此提供源代码。 使用最新的堆栈交换库。
【问题讨论】:
标签: asp.net-core-webapi .net-6.0 stackexchange.redis
.net 6 和 Redis 缓存集成使用集合、散列。 请为此提供源代码。 使用最新的堆栈交换库。
【问题讨论】:
标签: asp.net-core-webapi .net-6.0 stackexchange.redis
这是一个简单的存档演示,大家可以看看:
程序.cs:
builder.Services.AddStackExchangeRedisCache(options => {
options.Configuration = "127.0.0.1:6379";
});
builder.Services.AddSession();
app.UseSession();
控制器:
[ApiController]
public class TestController : Controller
{
private readonly IDistributedCache _distributedCache;
public TestController(IDistributedCache distributedCache)
{
_distributedCache = distributedCache;
}
[HttpGet]
[Route("test")]
public void Test()
{
const string key = "message";
const string value = "hello";
_distributedCache.SetString(key, value);
}
}
结果:
更多例子可以参考这篇文章:
【讨论】: