在 ASP.NET Core 控制器中使用 StackExchange.Redis [英] Using StackExchange.Redis in a ASP.NET Core Controller

查看:27
本文介绍了在 ASP.NET Core 控制器中使用 StackExchange.Redis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Redis 功能,例如来自 MVC 控制器的位域和哈希域.我知道 ASP 中有内置缓存支持.NET 核心,但这仅支持基本的 GET 和 SET 命令,不支持我的应用程序中需要的命令.我知道如何从普通(例如控制台)应用程序中使用 StackExchange.Redis,但我不确定如何在 ASP 站点中设置它.

I'd like to use Redis features such as bitfields and hashfields from an MVC controller. I understand there's built in caching support in ASP.NET core but this only supports basic GET and SET commands, not the commands that I need in my application. I know how to use StackExchange.Redis from a normal (eg. console) application, but I'm not sure how to set it up in an ASP site.

我应该把所有的连接初始化代码放在哪里,以便之后我可以从控制器访问它?这是我会使用依赖注入的东西吗?

Where should I put all the connection initialization code so that I can have access to it afterwards from a controller? Is this something I would use dependency injection for?

推荐答案

这个博客有一篇文章(附有完整代码存储库)关于在 ASP.NET Core 中实现 redis 服务.它有一个样板服务,可以自动将 POCO 类序列化为 redis 哈希集.

This blog has a writeup (with accompanying full code repo) about implementing a redis service into ASP.NET Core. It has a boilerplate service that automatically serialises POCO classes into a redis hashset.

这篇关于在 ASP.NET Core 控制器中使用 StackExchange.Redis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆