Sha256: 69030d6614b060b416bf5ad1d8905011a871a6c88e99ad4c11cc145114a9b282
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
require 'redis_dedupe/version' module RedisDedupe class<<self attr_accessor :client end class Set SEVEN_DAYS = 7 * 24 * 60 * 60 attr_reader :key, :expires_in def initialize(redis, key, expires_in = SEVEN_DAYS) @redis = redis @key = key @expires_in = expires_in end def check(member) results = redis.pipelined do redis.sadd(key, member) redis.expire(key, expires_in) end if results[0] yield end end def finish redis.unlink(key) end private def redis @redis end end module Helpers private def dedupe @dedupe ||= RedisDedupe::Set.new(RedisDedupe.client, [dedupe_namespace, dedupe_id].join(':')) end # Implement in class, should return an integer or string: # # Ex. # # def dedupe_id # @announcement.id # => 42 # end # def dedupe_id raise NotImplementedError end def dedupe_namespace self.class.name end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redis_dedupe-0.0.4 | lib/redis_dedupe.rb |