Module: RedisHash::Accessors
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/redis_hash/concerns/accessors.rb
Instance Method Summary collapse
- #[](field) ⇒ Object
- #fetch(field, default = nil) ⇒ Object
- #keys ⇒ Object
- #length ⇒ Object (also: #size)
- #values ⇒ Object
- #values_at(*fields) ⇒ Object
Instance Method Details
#[](field) ⇒ Object
13 14 15 |
# File 'lib/redis_hash/concerns/accessors.rb', line 13 def [](field) hget(redis_key, field) || default(field) end |
#fetch(field, default = nil) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/redis_hash/concerns/accessors.rb', line 17 def fetch(field, default = nil) value = self[field] return value if value.present? return yield(field) if block_given? return default unless default.nil? raise KeyError, "key not found: \"#{field}\"" end |
#keys ⇒ Object
26 27 28 |
# File 'lib/redis_hash/concerns/accessors.rb', line 26 def keys hkeys(redis_key) end |
#length ⇒ Object Also known as: size
30 31 32 |
# File 'lib/redis_hash/concerns/accessors.rb', line 30 def length hlen(redis_key) end |
#values ⇒ Object
35 36 37 |
# File 'lib/redis_hash/concerns/accessors.rb', line 35 def values hvals(redis_key) end |
#values_at(*fields) ⇒ Object
39 40 41 |
# File 'lib/redis_hash/concerns/accessors.rb', line 39 def values_at(*fields) hmget(*fields.flatten.unshift(redis_key)) end |