Class: Subduino::Store
- Inherits:
-
Object
- Object
- Subduino::Store
- Defined in:
- lib/subduino/store.rb
Class Method Summary collapse
- .add_csv_to_store(csv, stamp = false) ⇒ Object
- .add_to_store(key, val = nil) ⇒ Object
- .all ⇒ Object
- .count ⇒ Object
- .flush ⇒ Object
- .read(key) ⇒ Object
-
.read_hist(key, period, offset = 0, max = 100) ⇒ Object
SORT key [BY pattern] [LIMIT start count] [GET pattern] [ASC|DESC] [ALPHA] [STORE dstkey].
- .redis ⇒ Object
- .timestamp ⇒ Object
- .write(k, v, stamp = false) ⇒ Object
Class Method Details
.add_csv_to_store(csv, stamp = false) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/subduino/store.rb', line 40 def add_csv_to_store(csv, stamp = false) Log.info "[STORE] CSV #{Time.now.to_i}" csv.split(",").each do |d| comm, value = d.split(":") write(comm, value, stamp) end end |
.add_to_store(key, val = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/subduino/store.rb', line 30 def add_to_store(key, val=nil) if val write key, val else key.each do |k,v| write k, v end end end |
.all ⇒ Object
63 64 65 |
# File 'lib/subduino/store.rb', line 63 def all redis.keys end |
.count ⇒ Object
54 55 56 |
# File 'lib/subduino/store.rb', line 54 def count redis.dbsize end |
.flush ⇒ Object
58 59 60 61 |
# File 'lib/subduino/store.rb', line 58 def flush redis.flushdb #redis.flushall end |
.read(key) ⇒ Object
16 17 18 |
# File 'lib/subduino/store.rb', line 16 def read(key) redis.get key end |
.read_hist(key, period, offset = 0, max = 100) ⇒ Object
SORT key [BY pattern] [LIMIT start count] [GET pattern]
- ASC|DESC
- ALPHA
- STORE dstkey
50 51 52 |
# File 'lib/subduino/store.rb', line 50 def read_hist(key, period, offset = 0, max = 100) redis.sort key, { :order => 'desc', :limit => [offset, max] } end |
.redis ⇒ Object
12 13 14 |
# File 'lib/subduino/store.rb', line 12 def redis @redis ||= Redis.new(:timeout => 0) rescue false end |
.timestamp ⇒ Object
20 21 22 |
# File 'lib/subduino/store.rb', line 20 def Time.now.to_i.to_s end |
.write(k, v, stamp = false) ⇒ Object
24 25 26 27 |
# File 'lib/subduino/store.rb', line 24 def write(k, v, stamp = false) return unless redis #.connected? stamp ? redis.rpush("#{k}_log", "#{}:#{v}") : redis.set(k, v) end |