Class: Stockr::Store
- Inherits:
-
Object
- Object
- Stockr::Store
- Defined in:
- lib/stockr/store.rb
Class Method Summary collapse
- .connect! ⇒ Object
- .db ⇒ Object
- .find(txt) ⇒ Object
- .flush ⇒ Object
- .run(coe) ⇒ Object
- .write(key, values) ⇒ Object
Class Method Details
.connect! ⇒ Object
8 9 10 11 |
# File 'lib/stockr/store.rb', line 8 def connect! @db = Redis.new true end |
.db ⇒ Object
13 14 15 |
# File 'lib/stockr/store.rb', line 13 def db @@db ||= Redis.new end |
.find(txt) ⇒ Object
17 18 19 20 21 |
# File 'lib/stockr/store.rb', line 17 def find(txt) res = db.keys(txt) return nil if res.empty? res.sort.reduce({}) { |h, r| h.merge(r => db.hgetall(r)) } end |
.flush ⇒ Object
31 32 33 |
# File 'lib/stockr/store.rb', line 31 def flush db.flushall end |
.run(coe) ⇒ Object
27 28 29 |
# File 'lib/stockr/store.rb', line 27 def run(coe) db.send(code) end |
.write(key, values) ⇒ Object
23 24 25 |
# File 'lib/stockr/store.rb', line 23 def write(key, values) db.hmset(key, *values.to_a.flatten) end |