Distributed Locks with Heartbeats using Redis
When building highly available services, it's common to need to lock a resource every once in a while. You can use Redis and a simple wrapper to create a heartbeat/watchdog that will keep a lock alive as long as a task is running, and automatically unlock the resource if the process dies.