.net 6和Redis缓存集成使用集合、散列。请为此提供源代码。使用最新的堆栈交换库。
发布于 2022-02-10 08:05:04
下面是一个简单的保存演示,您可以查看:
Program.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);
}
}结果:

关于更多的例子,您可以参考本文:
https://stackoverflow.com/questions/71029079
复制相似问题