Class: Angus::Authentication::RedisStore
- Inherits:
-
Object
- Object
- Angus::Authentication::RedisStore
- Defined in:
- lib/angus/authentication/redis_store.rb
Constant Summary collapse
- DEFAULT_NAMESPACE =
''
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.
- #redis ⇒ Object
- #save_session_data(key, data, ttl) ⇒ Object
Constructor Details
#initialize(settings) ⇒ RedisStore
Returns a new instance of RedisStore.
11 12 13 14 15 |
# File 'lib/angus/authentication/redis_store.rb', line 11 def initialize(settings) settings = settings.dup @namespace = settings.delete(:namespace) || DEFAULT_NAMESPACE @settings = settings end |
Instance Method Details
#add_namespace(key) ⇒ Object
34 35 36 |
# File 'lib/angus/authentication/redis_store.rb', line 34 def add_namespace(key) "#@namespace.angus-authentication-provider.#{key}" end |
#get_session_data(key) ⇒ Object
26 27 28 |
# File 'lib/angus/authentication/redis_store.rb', line 26 def get_session_data(key) JSON(redis.get(add_namespace(key)) || {}) end |
#has_key?(key) ⇒ Boolean
17 18 19 |
# File 'lib/angus/authentication/redis_store.rb', line 17 def has_key?(key) redis.exists(add_namespace(key)) end |
#redis ⇒ Object
30 31 32 |
# File 'lib/angus/authentication/redis_store.rb', line 30 def redis @redis ||= Redis.new(@settings) end |
#save_session_data(key, data, ttl) ⇒ Object
21 22 23 24 |
# File 'lib/angus/authentication/redis_store.rb', line 21 def save_session_data(key, data, ttl) redis.set(add_namespace(key), JSON(data)) redis.expire(add_namespace(key), ttl) end |