title: How to set up Redis in custom namespace as cache and MQ on ServiceStack web application using Structuremap
body: <p>I want to set up my application to use Redis as Cache for sessions etc as well as run my Message Queues.</p>
  
  <p>My application is a ASP.net MVC website along with ServiceStack based Json service provider. What is the optimal way to configure?</p>
  
  <p>I want to be able to pass an IMessageQueueClient into my service classes and controllers so that I can add tasks to the queue.</p>
  
  <p>I'm getting somewhat lost over what scope to make what. My code is as follows:</p>
  
  <pre><code>//Redis Client Manager
  var pooledClientManager = new PooledRedisClientManager(ConfigurationManager.AppSettings.Get("RedisServer"));
  pooledClientManager.NamespacePrefix = "myApp-";
  For&lt;IRedisClientsManager&gt;().Singleton().Use(x =&gt; pooledClientManager);
  
  //Cache
  For&lt;ICacheClient&gt;().Use(c =&gt; c.GetInstance&lt;IRedisClientsManager&gt;().GetCacheClient());
  
  //MQ
  MyApplication.MqService = new RedisMqServer(pooledClientManager);
  For&lt;IMessageQueueClient&gt;().Singleton(). Use(
               x =&gt; MyApplication.MqService.CreateMessageQueueClient());
  For&lt;IMessageService&gt;().Singleton().Use(x=&gt;MyApplication.MqService);
  </code></pre>
  
  <p>I then later on call MyApplication.MqService.RegisterHandler(etc etc);</p>
  
  <ol>
  <li>This works but I'm not convinced I've got my scoping correct.</li>
  <li>The Namespace prefix doesn't work, and I need this feature.</li>
  </ol>
  
  <p>Thanks for your help with this!</p>