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.
49 50 51 52 |
# File 'lib/w3map.rb', line 49 def initialize(session_name, config={}) @session_name = session_name @redis = Redis.new(config) end |
Instance Method Details
#close ⇒ Object
68 69 70 |
# File 'lib/w3map.rb', line 68 def close @redis.quit end |
#flush ⇒ Object
65 66 67 |
# File 'lib/w3map.rb', line 65 def flush @redis.keys(schema('*')).each { |key| @redis.del key } end |
#read(key, field) ⇒ Object
59 60 61 |
# File 'lib/w3map.rb', line 59 def read(key, field) @redis.hget schema(key), field end |
#read_hash(key) ⇒ Object
62 63 64 |
# File 'lib/w3map.rb', line 62 def read_hash(key) @redis.hgetall schema(key) end |
#save(key, field, value) ⇒ Object
53 54 55 |
# File 'lib/w3map.rb', line 53 def save(key, field, value) @redis.hset schema(key), field, value end |
#save_hash(key, hash) ⇒ Object
56 57 58 |
# File 'lib/w3map.rb', line 56 def save_hash(key, hash) @redis.hmset schema(key), hash.flatten end |