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

查看:347
本文介绍了在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 initialisation 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天全站免登陆