How to set up Redis in custom namespace as cache and MQ on ServiceStack web application using Structuremap

房东的猫 提交于 2019-12-11 02:12:19

问题


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

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

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);

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

  1. This works but I'm not convinced I've got my scoping correct.
  2. The Namespace prefix doesn't work, and I need this feature.

Thanks for your help with this!


回答1:


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



来源:https://stackoverflow.com/questions/19095348/how-to-set-up-redis-in-custom-namespace-as-cache-and-mq-on-servicestack-web-appl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!