Class: FluShot::Storage::Redis
- Inherits:
-
Object
- Object
- FluShot::Storage::Redis
- Defined in:
- lib/flu_shot/storage/redis.rb
Instance Method Summary collapse
- #add(prescription, vaccines) ⇒ Object
- #get(name) ⇒ Object
-
#initialize(connection) ⇒ Redis
constructor
A new instance of Redis.
- #reset ⇒ Object
Constructor Details
#initialize(connection) ⇒ Redis
Returns a new instance of Redis.
7 8 9 |
# File 'lib/flu_shot/storage/redis.rb', line 7 def initialize(connection) @connection = connection end |
Instance Method Details
#add(prescription, vaccines) ⇒ Object
11 12 13 14 |
# File 'lib/flu_shot/storage/redis.rb', line 11 def add(prescription, vaccines) vaccines = [vaccines] unless vaccines.is_a?(Array) @connection.hset('flu_shot', prescription.to_s, YAML.dump(vaccines)) end |
#get(name) ⇒ Object
16 17 18 19 |
# File 'lib/flu_shot/storage/redis.rb', line 16 def get(name) value = @connection.hget('flu_shot', name) value ? YAML.load(value) : [] end |
#reset ⇒ Object
21 22 23 24 25 |
# File 'lib/flu_shot/storage/redis.rb', line 21 def reset @connection.hgetall('flu_shot').each_key do |x| @connection.hdel('flu_shot', x) end end |