Class: Stockr::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/stockr/store.rb

Class Method Summary collapse

Class Method Details

.connect!Object



8
9
10
11
# File 'lib/stockr/store.rb', line 8

def connect!
  @db = Redis.new
  true
end

.dbObject



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

.flushObject



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