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