Class: RedisDedupe::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_dedupe.rb

Constant Summary collapse

SEVEN_DAYS =
7 * 24 * 60 * 60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis, key, expires_in = SEVEN_DAYS) ⇒ Set

Returns a new instance of Set.



13
14
15
16
17
# File 'lib/redis_dedupe.rb', line 13

def initialize(redis, key, expires_in = SEVEN_DAYS)
  @redis      = redis
  @key        = key
  @expires_in = expires_in
end

Instance Attribute Details

#expires_inObject (readonly)

Returns the value of attribute expires_in.



11
12
13
# File 'lib/redis_dedupe.rb', line 11

def expires_in
  @expires_in
end

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/redis_dedupe.rb', line 11

def key
  @key
end

Instance Method Details

#check(member) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/redis_dedupe.rb', line 19

def check(member)
  results = redis.pipelined do |pipeline|
    pipeline.sadd?(key, member)
    pipeline.expire(key, expires_in)
  end

  if results[0]
    yield
  end
end

#finishObject



30
31
32
# File 'lib/redis_dedupe.rb', line 30

def finish
  redis.unlink(key)
end