lib/once.rb in once-0.0.3 vs lib/once.rb in once-0.0.4

- old
+ new

@@ -35,18 +35,10 @@ # params: The params that will control whether or not the body executes def do(name:, params:, within: DEFAULT_TIME, &block) hash = Digest::MD5.hexdigest(params.inspect) redis_key = "uniquecheck:#{name}:#{hash}" - perform(redis_key, &block).tap do - redis.setex(redis_key, within, true) - end - end - - private - - def perform(redis_key, &block) - unless redis.exists(redis_key) + if redis.set(redis_key, true, ex: within, nx: true) block.call end end end end