Method: Redis::HashKey#fetch

Defined in:
lib/redis/hash_key.rb

#fetch(field, *args, &block) ⇒ Object

Fetch a key in a way similar to Ruby's Hash#fetch



48
49
50
51
52
53
54
55
# File 'lib/redis/hash_key.rb', line 48

def fetch(field, *args, &block)
  value = hget(field)
  default = args[0]

  return value if value || (!default && !block_given?)

  block_given? ? block.call(field) : default
end