title: Use hmset / hmget in REDIS: WRONGTYPE Operation against a key holding the wrong kind of value
body: <p>I am trying to use hmset / hmget to store hashmaps associated to a key in REDIS as such:</p>
  
  <pre><code>def self.store_id_and_phone(id, phone)
    key = generate_key
    REDIS.hmset(key, :id, id, :phone, phone)
    REDIS.expire(key, 15.minutes)
    verification_code_url_key
  end
  
  def self.generate_key
    return ActiveSupport::SecureRandom.urlsafe_base64(5)
  end
  
  def self.get_id_and_phone(key)
    return REDIS.hmget(key, :id, :phone)
  end
  </code></pre>
  
  <p>However I sometimes get this error at <code>REDIS.hmget</code></p>
  
  <blockquote>
    <p>WRONGTYPE Operation against a key holding the wrong kind of value</p>
  </blockquote>
  
  <p>It doesn't happen all the time tho, <strong>about 3% of all the requests</strong>.</p>
  
  <p>Did anyone encounter similar issues before? Please shed some light. Thanks!</p>