
Show HN: Lock and cache using Redis - seamusabshere
https://github.com/seamusabshere/lock_and_cache
======
jconley
So this is for read through caching with distributed locking. There are a
couple scenarios where this is interesting.

1) If calculating the item in the cache is so expensive to some system, and
might happen so many times concurrently, that you'd rather block than
duplicate work. 2) There is something not-idempotent about the operation you
are blocking on.

But, coming from experience, be very very very very careful with distributed
locking and put lots of logging/monitoring/timeouts around it if you have to
do it. Avoid it if possible. Try hard to use a different persistent data
structure, store, or algorithm that makes the locking irrelevant.

------
AznHisoka
I already use Redis-Mutex for such use cases: [https://github.com/kenn/redis-
mutex](https://github.com/kenn/redis-mutex)

What's the difference?

~~~
jconley
Looks like this uses a Ruby version of redlock under the hood:
[http://redis.io/topics/distlock](http://redis.io/topics/distlock)

Seems to be just a little abstraction so you don't manage the locks yourself.

------
troutwine
Hmm, wait, maybe I'm misunderstanding. Why would you want to serialize all
concurrent actors on a cache read?

~~~
gkop
It only serializes on a cache miss.

~~~
troutwine
That's what I was missing. Thanks!

