Class: MailRoom::Arbitration::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_room/arbitration/redis.rb

Defined Under Namespace

Classes: Options

Constant Summary collapse

EXPIRATION =

Expire after 10 minutes so Redis doesn't get filled up with outdated data.

600

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Redis

Returns a new instance of Redis.


21
22
23
# File 'lib/mail_room/arbitration/redis.rb', line 21

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options


19
20
21
# File 'lib/mail_room/arbitration/redis.rb', line 19

def options
  @options
end

Instance Method Details

#deliver?(uid, expiration = EXPIRATION) ⇒ Boolean

Returns:

  • (Boolean)

25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mail_room/arbitration/redis.rb', line 25

def deliver?(uid, expiration = EXPIRATION)
  key = "delivered:#{uid}"

  # Set the key, but only if it doesn't already exist;
  # the return value is true if successful, false if the key was already set,
  # which is conveniently the correct return value for this method
  # Any subsequent failure in the instance which gets the lock will be dealt
  # with by the expiration, at which time another instance can pick up the
  # message and try again.
  client.set(key, 1, {:nx => true, :ex => expiration})
end