title: How to merge a Redis hash and a Rails record?
body: <p>For example, I have a shopping cart(redis hash) which contains a product id and a count:</p>
  
  <pre><code>{"165"=&gt;"2", "166"=&gt;"3"}
  </code></pre>
  
  <p>How do I find all products with these ids?
  I think something like that:</p>
  
  <p>1) <code>Product.where(id: hash.keys)</code> , but then I lose the <code>count</code>.</p>
  
  <p>2) I can iterate the hash:</p>
  
  <pre><code>@products = []
  
  hash.each do |id, count|
    product = Product.find(id)
    @products &lt;&lt; product
  end
  </code></pre>
  
  <p>But I don't know how to add count param in the <code>product</code> record and I think this approach is inefficient, because I'll get O(N) queries.</p>
  
  <p>How to solve this problem?</p>