Joined March 2012
·

Erol Fornoles

Software Craftsman at Deal Grocer
·
San Pedro, Laguna
·
·
·

I'd recommend this form:

def foo
  return @cache if defined? @cache
  @cache = some_expensive_operation
end

This even handles scenarios when some_expensive_operation validly returns nil

Posted to Writing a queue system in Redis over 1 year ago

Looks like I worded that poorly. Since the queue is built on top of a zset, calling zadd will always result in a unique set and a setnx call is no longer necessary. Zadd also has a behavior which I found useful: calling zadd with an existing member updates the member's score and reorders the zset, allowing an event to be "rescheduled" to a different time.

I'll post a writeup later. You can also browse the code here: https://github.com/Erol/later.

Posted to Writing a queue system in Redis over 1 year ago

I wrote a lightweight event scheduling library, and the events/payload added had to be unique and run on a scheduled time. I've managed to avoid the use of setnx by using a zset queue; the zset handles both scenarios nicely by it being a set and having scores.

Achievements
283 Karma
16,115 Total ProTip Views