title: How to set data in redis hash using ruby
body: <p>Currently I am caching data from active record to redis by doing following:</p>
  
  <p><strong>redis.rb</strong></p>
  
  <pre><code>$redis = Redis::Namespace.new("bookstore", :redis =&gt; Redis.new)
  </code></pre>
  
  <p><strong>authors_helper.rb</strong></p>
  
  <pre><code>def fetch_authors
      authors = $redis.get('authors')
      if authors.nil?
        authors = Author.all.to_json
        $redis.set("authors", authors).to_json
        $redis.expire("authors", 5.hour.to_i)
      end
      JSON.load authors
  end
  </code></pre>
  
  <p>So currently I am using basic <code>set</code> and <code>get</code> to cache and read data from redis.</p>
  
  <p>I want to use <code>hmset</code> instead of just <code>set</code>. The redis way to to this job is as follows:</p>
  
  <p>(Just an example)</p>
  
  <pre><code>HMSET user:1001 name "Mary Jones" password "hidden" email "mjones@example.com"
  </code></pre>
  
  <p>The <strong>authors</strong> table in my app consists of following field: <code>id</code> ,<code>name</code>, <code>created_at</code>, <code>updated_at</code></p>
  
  <p>What is the ruby way to use <code>hmset</code> so that I can cache <code>authors</code> data in a redis hash?</p>