Class: Angus::Authentication::RedisStore
- Inherits:
-
Object
- Object
- Angus::Authentication::RedisStore
- Defined in:
- lib/angus/authentication/redis_store.rb
Constant Summary collapse
- DEFAULT_NAMESPACE =
''- REDIS_POOL_SIZE =
10- REDIS_POOL_TIMEOUT =
5
Instance Method Summary collapse
- #add_namespace(key) ⇒ Object
- #get_session_data(key) ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize(settings) ⇒ RedisStore
constructor
A new instance of RedisStore.
- #pool_settings ⇒ Object
- #redis ⇒ Object
- #save_session_data(key, data, ttl) ⇒ Object
Constructor Details
#initialize(settings) ⇒ RedisStore
Returns a new instance of RedisStore.
14 15 16 17 18 19 20 |
# File 'lib/angus/authentication/redis_store.rb', line 14 def initialize(settings) settings = settings.dup @namespace = settings.delete(:namespace) || DEFAULT_NAMESPACE @pool_size = settings.delete(:pool_size) || REDIS_POOL_SIZE @pool_timeout = settings.delete(:pool_timeout) || REDIS_POOL_TIMEOUT @settings = settings end |
Instance Method Details
#add_namespace(key) ⇒ Object
47 48 49 |
# File 'lib/angus/authentication/redis_store.rb', line 47 def add_namespace(key) "#@namespace.angus-authentication-provider.#{key}" end |
#get_session_data(key) ⇒ Object
33 34 35 36 |
# File 'lib/angus/authentication/redis_store.rb', line 33 def get_session_data(key) data = redis.with { |connection| connection.get(add_namespace(key)) } || '{}' JSON(data) end |
#has_key?(key) ⇒ Boolean
22 23 24 |
# File 'lib/angus/authentication/redis_store.rb', line 22 def has_key?(key) redis.with { |connection| connection.exists(add_namespace(key)) } end |
#pool_settings ⇒ Object
42 43 44 45 |
# File 'lib/angus/authentication/redis_store.rb', line 42 def pool_settings { :size => @pool_size, :timeout => @pool_timeout } end |
#redis ⇒ Object
38 39 40 |
# File 'lib/angus/authentication/redis_store.rb', line 38 def redis @redis ||= ConnectionPool.new(pool_settings) { Redis.new(@settings) } end |
#save_session_data(key, data, ttl) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/angus/authentication/redis_store.rb', line 26 def save_session_data(key, data, ttl) redis.with do |connection| connection.set(add_namespace(key), JSON(data)) connection.expire(add_namespace(key), ttl) end end |