Class: Resque::Integration::Ordered::Uniqueness

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/integration/ordered.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Uniqueness

Returns a new instance of Uniqueness.



49
50
51
# File 'lib/resque/integration/ordered.rb', line 49

def initialize(&block)
  @unique_block = block
end

Instance Method Details

#encoded_unique_args(args) ⇒ Object



65
66
67
# File 'lib/resque/integration/ordered.rb', line 65

def encoded_unique_args(args)
  Resque.encode(@unique_block.call(*args))
end

#key(meta_id) ⇒ Object



53
54
55
# File 'lib/resque/integration/ordered.rb', line 53

def key(meta_id)
  "ordered:unique:#{meta_id}"
end

#ordered_meta_id(meta_id, args) ⇒ Object



69
70
71
# File 'lib/resque/integration/ordered.rb', line 69

def ordered_meta_id(meta_id, args)
  Resque.redis.hget(key(meta_id), encoded_unique_args(args))
end

#remove(meta_id, args) ⇒ Object



57
58
59
# File 'lib/resque/integration/ordered.rb', line 57

def remove(meta_id, args)
  Resque.redis.hdel(key(meta_id), encoded_unique_args(args))
end

#set(meta_id, args, ordered_meta_id) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/resque/integration/ordered.rb', line 73

def set(meta_id, args, ordered_meta_id)
  unique_key = key(meta_id)

  if Resque.redis.hset(unique_key, encoded_unique_args(args), ordered_meta_id)
    Resque.redis.expire(unique_key, ARGS_EXPIRATION)
  end
end

#size(meta_id) ⇒ Object



61
62
63
# File 'lib/resque/integration/ordered.rb', line 61

def size(meta_id)
  Resque.redis.hlen(key(meta_id)).to_i
end