如何使用 Structuremap 在 ServiceStack Web 应用程序上将自定义命名空间中的 Redis 设置为缓存和 MQ [英] How to set up Redis in custom namespace as cache and MQ on ServiceStack web application using Structuremap

查看:52
本文介绍了如何使用 Structuremap 在 ServiceStack Web 应用程序上将自定义命名空间中的 Redis 设置为缓存和 MQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置我的应用程序以使用 Redis 作为会话等的缓存以及运行我的消息队列.

I want to set up my application to use Redis as Cache for sessions etc as well as run my Message Queues.

我的应用程序是一个 ASP.net MVC 网站以及基于 ServiceStack 的 Json 服务提供者.最佳配置方式是什么?

My application is a ASP.net MVC website along with ServiceStack based Json service provider. What is the optimal way to configure?

我希望能够将 IMessageQueueClient 传递到我的服务类和控制器中,以便我可以将任务添加到队列中.

I want to be able to pass an IMessageQueueClient into my service classes and controllers so that I can add tasks to the queue.

我对制作什么的范围有些迷茫.我的代码如下:

I'm getting somewhat lost over what scope to make what. My code is as follows:

//Redis Client Manager
var pooledClientManager = new PooledRedisClientManager(ConfigurationManager.AppSettings.Get("RedisServer"));
pooledClientManager.NamespacePrefix = "myApp-";
For<IRedisClientsManager>().Singleton().Use(x => pooledClientManager);

//Cache
For<ICacheClient>().Use(c => c.GetInstance<IRedisClientsManager>().GetCacheClient());

//MQ
MyApplication.MqService = new RedisMqServer(pooledClientManager);
For<IMessageQueueClient>().Singleton(). Use(
             x => MyApplication.MqService.CreateMessageQueueClient());
For<IMessageService>().Singleton().Use(x=>MyApplication.MqService);

我稍后调用 MyApplication.MqService.RegisterHandler(etc etc);

I then later on call MyApplication.MqService.RegisterHandler(etc etc);

  1. 这行得通,但我不相信我的范围是正确的.
  2. 命名空间前缀不起作用,我需要此功能.

感谢您对此的帮助!

推荐答案

NamespacePrefix 仅用于 RedisClients 维护的内部数据结构,不影响用户指定的键.

The NamespacePrefix is only for internal data-structures maintained by the RedisClients and doesn't affect user-specified keys.

这篇关于如何使用 Structuremap 在 ServiceStack Web 应用程序上将自定义命名空间中的 Redis 设置为缓存和 MQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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