Class: Resque::Integration::Ordered::Uniqueness
- Inherits:
-
Object
- Object
- Resque::Integration::Ordered::Uniqueness
- Defined in:
- lib/resque/integration/ordered.rb
Instance Method Summary collapse
- #encoded_unique_args(args) ⇒ Object
-
#initialize(&block) ⇒ Uniqueness
constructor
A new instance of Uniqueness.
- #key(meta_id) ⇒ Object
- #ordered_meta_id(meta_id, args) ⇒ Object
- #remove(meta_id, args) ⇒ Object
- #set(meta_id, args, ordered_meta_id) ⇒ Object
- #size(meta_id) ⇒ Object
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() "ordered:unique:#{}" end |
#ordered_meta_id(meta_id, args) ⇒ Object
69 70 71 |
# File 'lib/resque/integration/ordered.rb', line 69 def (, args) Resque.redis.hget(key(), encoded_unique_args(args)) end |
#remove(meta_id, args) ⇒ Object
57 58 59 |
# File 'lib/resque/integration/ordered.rb', line 57 def remove(, args) Resque.redis.hdel(key(), 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(, args, ) unique_key = key() if Resque.redis.hset(unique_key, encoded_unique_args(args), ) 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() Resque.redis.hlen(key()).to_i end |