Module: RedisModel::Types::Hash
- Includes:
- Base
- Defined in:
- lib/redis_model/types/hash.rb
Overview
Internal: Methods for hash type of key in Redis.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Public: Retrieves a key in Hash using Redis HGET command.
-
#[]=(key, value) ⇒ Object
Public: Sets a key in Hash using Redis HSET command.
-
#incr(key, by = 1) ⇒ Object
Public: Increments a key in Hash using Redis HINCRBY command.
- #keys ⇒ Object
- #to_hash ⇒ Object
Methods included from Base
Instance Method Details
#[](key) ⇒ Object
Public: Retrieves a key in Hash using Redis HGET command.
key - Key to retrieve.
Returns retrieved value.
26 27 28 |
# File 'lib/redis_model/types/hash.rb', line 26 def [](key) connection.hget(key_label, key.to_s) end |
#[]=(key, value) ⇒ Object
Public: Sets a key in Hash using Redis HSET command.
key - Key to set. value - Value to set.
Returns new value.
13 14 15 16 17 18 19 |
# File 'lib/redis_model/types/hash.rb', line 13 def []=(key, value) result = connection.hset(key_label, key.to_s, value) @cached_hash = nil value end |
#incr(key, by = 1) ⇒ Object
Public: Increments a key in Hash using Redis HINCRBY command.
key - Key to increment. by - Amount for increment (default: 1)
Returns incremented value.
36 37 38 39 40 41 42 |
# File 'lib/redis_model/types/hash.rb', line 36 def incr(key, by = 1) result = connection.hincrby(key_label, key, by) @cached_hash = nil result.to_i end |
#keys ⇒ Object
48 49 50 |
# File 'lib/redis_model/types/hash.rb', line 48 def keys connection.hkeys(key_label) end |
#to_hash ⇒ Object
44 45 46 |
# File 'lib/redis_model/types/hash.rb', line 44 def to_hash @cached_hash ||= connection.hgetall(key_label) end |