Class: Kredis::Types::Hash
Instance Attribute Summary collapse
Attributes inherited from Proxying
#key, #proxy, #redis
Instance Method Summary
collapse
Methods inherited from Proxying
#failsafe, #initialize, proxying
Instance Attribute Details
#typed ⇒ Object
Returns the value of attribute typed.
6
7
8
|
# File 'lib/kredis/types/hash.rb', line 6
def typed
@typed
end
|
Instance Method Details
#[](key) ⇒ Object
8
9
10
|
# File 'lib/kredis/types/hash.rb', line 8
def [](key)
string_to_type(hget(key), typed)
end
|
#[]=(key, value) ⇒ Object
12
13
14
|
# File 'lib/kredis/types/hash.rb', line 12
def []=(key, value)
update key => value
end
|
#delete(*keys) ⇒ Object
24
25
26
|
# File 'lib/kredis/types/hash.rb', line 24
def delete(*keys)
hdel keys if keys.flatten.any?
end
|
#entries ⇒ Object
Also known as:
to_h
32
33
34
|
# File 'lib/kredis/types/hash.rb', line 32
def entries
(hgetall || {}).transform_values { |val| string_to_type(val, typed) }.with_indifferent_access
end
|
#keys ⇒ Object
37
38
39
|
# File 'lib/kredis/types/hash.rb', line 37
def keys
hkeys || []
end
|
#remove ⇒ Object
28
29
30
|
# File 'lib/kredis/types/hash.rb', line 28
def remove
del
end
|
#update(**entries) ⇒ Object
16
17
18
|
# File 'lib/kredis/types/hash.rb', line 16
def update(**entries)
hset entries.transform_values{ |val| type_to_string(val, typed) } if entries.flatten.any?
end
|
#values ⇒ Object
41
42
43
|
# File 'lib/kredis/types/hash.rb', line 41
def values
strings_to_types(hvals || [], typed)
end
|
#values_at(*keys) ⇒ Object
20
21
22
|
# File 'lib/kredis/types/hash.rb', line 20
def values_at(*keys)
strings_to_types(hmget(keys) || [], typed)
end
|