Created
February 2, 2012 05:44
-
-
Save stevenkuhn/1721753 to your computer and use it in GitHub Desktop.
Triggering events in a Windows Service from an ASP.NET site using Redis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void ProcessEvents() { | |
using (var client = redisManager.GetClient()) { | |
// incoming events are JSON, so deserialize each one to IDictionary<>. | |
var events = client.GetTypedClient<IDictionary<string, object>>().Lists["urn:events"]; | |
while (true) { | |
// wait for next event, then convert it to an ExpandoObject; | |
dynamic @event = events.BlockingDequeue(null).ToExpando(); | |
if (@event.Name == "User.ForgotPassword") | |
SendForgottenPasswordEmail(@event.Email); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kernel.Bind<IRedisClientsManager>() | |
// BasicRedisClientManager | |
// - use when the redis server and client are on the same host. | |
// PooledRedisClientManager | |
// - use when the redis server and client are on different hosts. | |
.To<BasicRedisClientManager>() | |
.InSingletonScope() | |
.WithConstructorArgument("readWriteHosts", new string[] { "localhost:6379" }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserController : Controller { | |
private IRedisClientManager redisManager; | |
[HttpPost] | |
public ActionResult ForgotPassword(string email) { | |
using (var client = redisManager.GetClient()) { | |
// each event is automatically serialized to JSON | |
var events = client.GetTypedClient<dynamic>().Lists["urn:events"]; | |
events.Enqueue(new | |
{ | |
Name = "User.ForgotPassword", | |
Email = email | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment