Class: W3map::DataStore

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

Instance Method Summary collapse

Constructor Details

#initialize(session_name, config = {}) ⇒ DataStore

Returns a new instance of DataStore.



36
37
38
39
# File 'lib/w3map.rb', line 36

def initialize(session_name, config={})
  @session_name = session_name
  @redis = Redis.new(config)
end

Instance Method Details

#closeObject



55
56
57
# File 'lib/w3map.rb', line 55

def close
  @redis.quit
end

#flushObject



52
53
54
# File 'lib/w3map.rb', line 52

def flush
  @redis.keys(schema('*')).each { |key| @redis.del key }
end

#read(key, field) ⇒ Object



46
47
48
# File 'lib/w3map.rb', line 46

def read(key, field)
  @redis.hget schema(key), field
end

#read_hash(key) ⇒ Object



49
50
51
# File 'lib/w3map.rb', line 49

def read_hash(key)
  @redis.hgetall schema(key)
end

#save(key, field, value) ⇒ Object



40
41
42
# File 'lib/w3map.rb', line 40

def save(key, field, value)
  @redis.hset schema(key), field, value
end

#save_hash(key, hash) ⇒ Object



43
44
45
# File 'lib/w3map.rb', line 43

def save_hash(key, hash)
  @redis.hmset schema(key), hash.flatten
end