Class: RedHash
- Inherits:
-
Object
- Object
- RedHash
- Defined in:
- lib/redness/red_hash.rb
Instance Attribute Summary collapse
-
#hash_key ⇒ Object
Returns the value of attribute hash_key.
-
#redis ⇒ Object
Returns the value of attribute redis.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #all ⇒ Object
- #clear ⇒ Object
- #get(key) ⇒ Object
-
#initialize(hash_key = self.class.name, redis = Red.new) ⇒ RedHash
constructor
A new instance of RedHash.
- #remove(key) ⇒ Object
- #set(options) ⇒ Object
Constructor Details
Instance Attribute Details
#hash_key ⇒ Object
Returns the value of attribute hash_key.
2 3 4 |
# File 'lib/redness/red_hash.rb', line 2 def hash_key @hash_key end |
#redis ⇒ Object
Returns the value of attribute redis.
2 3 4 |
# File 'lib/redness/red_hash.rb', line 2 def redis @redis end |
Instance Method Details
#[](key) ⇒ Object
16 17 18 19 20 |
# File 'lib/redness/red_hash.rb', line 16 def [](key) redis.execute_with_uncertainty(nil) do redis.hget(hash_key, key) end end |
#[]=(key, value) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/redness/red_hash.rb', line 9 def []=(key, value) redis.execute_with_uncertainty(nil) do redis.hset(hash_key, key, value) value end end |
#all ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/redness/red_hash.rb', line 28 def all redis.execute_with_uncertainty({}) do hash = redis.hgetall(hash_key) HashWithIndifferentAccess.new(hash) end end |
#clear ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/redness/red_hash.rb', line 36 def clear redis.execute_with_uncertainty(false) do redis.hkeys(hash_key).each do |key| redis.hdel(hash_key, key) end end end |
#get(key) ⇒ Object
44 45 46 |
# File 'lib/redness/red_hash.rb', line 44 def get(key) self[key] end |
#remove(key) ⇒ Object
22 23 24 25 26 |
# File 'lib/redness/red_hash.rb', line 22 def remove(key) redis.execute_with_uncertainty(false) do redis.hdel(hash_key, key) end end |
#set(options) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/redness/red_hash.rb', line 48 def set() redis.execute_with_uncertainty(false) do .keys.each do |option| self[option] = [option] end end end |