Class: Mach::Persistence::RedisStore

Inherits:
DeltaAndNonceStore show all
Defined in:
lib/mach/persistence/redis_store.rb

Instance Method Summary collapse

Methods inherited from DeltaAndNonceStore

configure

Constructor Details

#initialize(options = {}) ⇒ RedisStore

Returns a new instance of RedisStore.



9
10
11
12
13
# File 'lib/mach/persistence/redis_store.rb', line 9

def initialize(options = {})
  raise Mach::Error::MissingConfigurationOptionError unless options[:host] && options[:port]
  @redis = Redis.new(:host => options[:host], :port => options[:port])
  @key_namespace = options[:key_namespace] || ""
end

Instance Method Details

#add_delta(credential_id, delta_value, expires_in) ⇒ Object



19
20
21
22
# File 'lib/mach/persistence/redis_store.rb', line 19

def add_delta(credential_id, delta_value, expires_in)
  @redis.setex(delta_key_for(credential_id), expires_in, delta_value)
  delta_value
end

#add_nonce(credential_id, nonce_value, expires_in) ⇒ Object



28
29
30
# File 'lib/mach/persistence/redis_store.rb', line 28

def add_nonce(credential_id, nonce_value, expires_in)
  @redis.setex(nonce_key_for(credential_id, nonce_value), expires_in, 1)
end

#find_delta_by(credential_id) ⇒ Object



15
16
17
# File 'lib/mach/persistence/redis_store.rb', line 15

def find_delta_by(credential_id)
  @redis.get(delta_key_for(credential_id))
end

#find_nonce_by(credential_id, nonce_value) ⇒ Object



24
25
26
# File 'lib/mach/persistence/redis_store.rb', line 24

def find_nonce_by(credential_id, nonce_value)
  @redis.get(nonce_key_for(credential_id, nonce_value))
end