Class: RedisStorageTokens::Storage
- Inherits:
-
Object
- Object
- RedisStorageTokens::Storage
- Defined in:
- lib/redis_storage_tokens.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
writeonly
Sets the attribute db.
Instance Method Summary collapse
- #add(key, value) ⇒ Object
- #delete(key) ⇒ Object
- #find(key) ⇒ Object
-
#initialize(redis_uri, namespace = :jwt) ⇒ Storage
constructor
A new instance of Storage.
Constructor Details
#initialize(redis_uri, namespace = :jwt) ⇒ Storage
Returns a new instance of Storage.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/redis_storage_tokens.rb', line 8 def initialize(redis_uri, namespace = :jwt) begin connection = Redis.new(url: redis_uri) connection.ping namespace = Redis::Namespace.new(namespace, redis: connection) @db = namespace rescue Errno::ECONNREFUSED => e puts "Error: Redis server unavailable. Shutting down..." exit 1 end end |
Instance Attribute Details
#db=(value) ⇒ Object
Sets the attribute db
20 21 22 |
# File 'lib/redis_storage_tokens.rb', line 20 def db=(value) @db = value end |
Instance Method Details
#add(key, value) ⇒ Object
25 26 27 |
# File 'lib/redis_storage_tokens.rb', line 25 def add( key, value ) @db.set(key,value) end |
#delete(key) ⇒ Object
33 34 35 |
# File 'lib/redis_storage_tokens.rb', line 33 def delete( key ) @db.del(key) end |
#find(key) ⇒ Object
29 30 31 |
# File 'lib/redis_storage_tokens.rb', line 29 def find( key ) @db.get(key) end |