Class: EpoOps::TokenStore::Redis

Inherits:
EpoOps::TokenStore show all
Defined in:
lib/epo_ops/token_store/redis.rb

Instance Method Summary collapse

Constructor Details

#initialize(redis_host) ⇒ Redis

Returns a new instance of Redis.



4
5
6
7
8
# File 'lib/epo_ops/token_store/redis.rb', line 4

def initialize(redis_host)
  fail "Please install gems 'redis' and 'connection_pool' to use this feature" unless defined?(::Redis) && defined?(ConnectionPool)

  @redis = ConnectionPool.new(size: 5, timeout: 5) { ::Redis.new(host: redis_host) }
end

Instance Method Details

#resetObject



19
20
21
22
23
# File 'lib/epo_ops/token_store/redis.rb', line 19

def reset
  @redis.with do |conn|
    conn.del("epo_token_#{id}")
  end
end

#tokenObject



10
11
12
13
14
15
16
17
# File 'lib/epo_ops/token_store/redis.rb', line 10

def token
  token = nil
  @redis.with do |conn|
    token = conn.get("epo_token_#{id}")
  end

  token.present? ? OAuth2::AccessToken.new(client, token) : generate_token
end