Method: Redis::Commands::Hashes#mapped_hmget

Defined in:
lib/redis/commands/hashes.rb

#mapped_hmget(key, *fields) ⇒ Hash

Get the values of all the given hash fields.

Examples:

redis.mapped_hmget("hash", "f1", "f2")
  # => { "f1" => "v1", "f2" => "v2" }

Parameters:

  • key (String)
  • fields (Array<String>)

    array of fields

Returns:

  • (Hash)

    a hash mapping the specified fields to their values

See Also:



105
106
107
108
109
110
111
112
113
114
# File 'lib/redis/commands/hashes.rb', line 105

def mapped_hmget(key, *fields)
  fields.flatten!(1)
  hmget(key, fields) do |reply|
    if reply.is_a?(Array)
      Hash[fields.zip(reply)]
    else
      reply
    end
  end
end