Class: RedisDedupe::Set
- Inherits:
-
Object
- Object
- RedisDedupe::Set
- Defined in:
- lib/redis_dedupe.rb
Constant Summary collapse
- SEVEN_DAYS =
7 * 24 * 60 * 60
Instance Attribute Summary collapse
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #check(member) ⇒ Object
- #finish ⇒ Object
-
#initialize(redis, key, expires_in = SEVEN_DAYS) ⇒ Set
constructor
A new instance of Set.
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_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
11 12 13 |
# File 'lib/redis_dedupe.rb', line 11 def expires_in @expires_in end |
#key ⇒ Object (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 |
#finish ⇒ Object
30 31 32 |
# File 'lib/redis_dedupe.rb', line 30 def finish redis.unlink(key) end |