title: How to configure Redis cache for session management with UUIDs
body: <p>I am attempting to configure Redis as cache layer in a Java application.  Specifically, the intended use of Redis will be to maintain session state.  Each user in the application would be represented by:</p>
  
  <ul>
  <li>a UUID corresponding to the session ID</li>
  <li>a userId value</li>
  <li>last access time</li>
  <li>and maybe a few other small fields</li>
  </ul>
  
  <p>I am confused about how to use Redis' hash.  The interface for <code>Jedis</code> is:</p>
  
  <pre><code>Jedis#hset(byte[] key, byte[] field, byte[] value)
  </code></pre>
  
  <p>That is, the Redis hash has a key, which in turn points to another map of fields and values.</p>
  
  <p>What design should I use to:</p>
  
  <ul>
  <li>Efficiently store each user's UUID in the hash</li>
  <li>Also take advantage of Redis' ability to expire entires</li>
  </ul>
  
  <p>To the second point above, if I wanted to expire an entry, it would have to be done at the key, and not field, level.  But, this would then imply that each UUID would have to be a separate key in the hash, and it is not clear whether that would be good Redis design.</p>