How to set up Redis in custom namespace as cache a

2019-07-20 04:34发布

问题:

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.