Class: W3map::DataStore
- Inherits:
-
Object
- Object
- W3map::DataStore
- Defined in:
- lib/w3map.rb
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(session_name, config = {}) ⇒ DataStore
constructor
A new instance of DataStore.
- #read(key, field) ⇒ Object
- #read_hash(key) ⇒ Object
- #save(key, field, value) ⇒ Object
- #save_hash(key, hash) ⇒ Object
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
#close ⇒ Object
55 56 57 |
# File 'lib/w3map.rb', line 55 def close @redis.quit end |
#flush ⇒ Object
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 |