class Aviator::SessionPool
Constants
- REDIS_KEY_PREFIX
- VERSION
Attributes
c[R]
configuration[R]
Public Class Methods
[](key)
click to toggle source
# File lib/aviator/session_pool/session_pool.rb, line 30 def [](key) session_dump = redis.get(build_key(key)) return nil unless session_dump session = Aviator::Session.load(session_dump) session.validate ? session : nil end
Also aliased as: get
[]=(key, session)
click to toggle source
# File lib/aviator/session_pool/session_pool.rb, line 23 def []=(key, session) session_key = build_key(key) redis.set(session_key, session.dump) end
configure(options)
click to toggle source
Not thread safe! BUT good enough for a single-threaded web application.
# File lib/aviator/session_pool/session_pool.rb, line 44 def configure(options) @configuration = options # So that the redis configuration will # be reloaded on the next ::redis call @redis = nil end
get_current()
click to toggle source
WARNING: Since get_current
uses a class instance variable, it will contain a value between http requests whether set_current
was called or not for as long as it was called at least once.
# File lib/aviator/session_pool/session_pool.rb, line 58 def get_current self.get(@current_key) || (raise CurrentSessionNotDefinedError.new) end
get_or_create(key, &block)
click to toggle source
# File lib/aviator/session_pool/session_pool.rb, line 63 def get_or_create(key, &block) # If session is invalid or does not exist, self[] will return nil unless session = self[key] config = configuration.dup [:redis_host, :redis_port].each{|k| config.delete k } session = Aviator::Session.new(config) session.authenticate &block self[key] = session end session end
set_current(key)
click to toggle source
Not thread safe! BUT good enough for a single-threaded web application.
# File lib/aviator/session_pool/session_pool.rb, line 81 def set_current(key) raise SessionNotFoundError.new(key) unless self.get(key) @current_key = key end
Private Class Methods
build_key(key)
click to toggle source
# File lib/aviator/session_pool/session_pool.rb, line 90 def build_key(key) "#{ REDIS_KEY_PREFIX }.#{ key }" end
redis()
click to toggle source
# File lib/aviator/session_pool/session_pool.rb, line 94 def redis @redis ||= Redis.new(host: c[:redis_host], port: c[:redis_port]) end